Page 1 of 1

problem with email form in html using php

Posted: Wed Aug 24, 2011 1:41 pm
by Cyberoxy
Hey there

I wrote php codes for processing to send email but I feel bit hopeless because when you click on send button after filling a form, you got message like "thank you for contacting us". It is working but I still dont receive this email. I have tested it and send to my email when clicked send button but email didnt come through.
I wonder what is wrong?

Maybe you can check out my codes and tell me where is error? I would appreciate your help.

HTML MARKUP (contactformpage.html)
<form name="form1" method="post" action="contactformprocess.php">
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td><label for="email">
<div align="right">Email Address:</div>
</label>
</td>
<td><div align="left">
<input name="email" type="text" id="email" size="35" maxlength="100">
</div></td>
</tr>
<tr>
<td><label for="name">
<div align="right">Name:</div>
</label>
</td>
<td><div align="left">
<input name="name" type="text" id="name" size="35" maxlength="80">
</div></td>
</tr>

<tr>
<td><div align="right">
<label for="comments">Comments:</label>
</div></td>
<td><div align="left">
<textarea name="comments" id="comments" cols="26" rows="5"></textarea>
</div></td>
</tr>
<tr>
<td><div align="right">
<label for="clear"></label>
<input type="reset" name="clear" id="clear" value="Reset Form">
</div></td>
<td><div align="right">
<label for="submit"></label>
<div align="left">
<input type="submit" name="submit" id="submit" value="Send Email!">
</div>
</div></td>
</tr>
</table>
</form>

PHP codes (contactformprocess.php)

<?php

$emailSubject = 'You got message from your website';
$webMaster = 'myname@lantic.net';

$email = $_POST['email'];
$name = $_POST['name'];
$comments = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Comments: $comments
EOD;

$headers = "Form:$email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

$theResults = <<<EOD
<html>
<head>
<title>Process</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>

<div>
<div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;

echo "$theResults";

?>

Re: problem with email form in html using php

Posted: Wed Aug 24, 2011 1:44 pm
by social_experiment
Try placing the From header after the content type header.

Re: problem with email form in html using php

Posted: Wed Aug 24, 2011 3:51 pm
by phphelpme
Dear me... lol its been a long time since I seen Heredoc being used. lol

Is that thing still being supported? lol :)

Best wishes

Re: problem with email form in html using php

Posted: Thu Aug 25, 2011 1:33 am
by social_experiment
phphelpme wrote:Heredoc
Is that the <<<EOD code?

Re: problem with email form in html using php

Posted: Thu Aug 25, 2011 2:44 am
by phphelpme
Yeah social, has been getting changed over the last couple of years and certain things are not allowed any more within the <<< ;

Check it out here:

http://www.php.net/manual/en/language.t ... ax.heredoc

Best wishes

Re: problem with email form in html using php

Posted: Thu Aug 25, 2011 2:51 am
by social_experiment
The first time i saw those was when i started learning about sending mail, never could get the script in the book to work until i veered away from heredoc. Thanks for the url :)

Re: problem with email form in html using php

Posted: Thu Aug 25, 2011 2:53 am
by phphelpme
I hate the thing anyway, cant believe it still gets used to be honest. lol

Its a little silly really because you have set stnadards of coding then heredoc goes against all that... lol

No worries about the link Social.

Best wishes