Mig Posted September 14, 2006 Share Posted September 14, 2006 Ok, I am sure contact form questions get asked here like 1000 times a day, but this really has me stumped.I just don't receive any emails. I tested the mail() function and it returns true so I don't know why I don't receive an email. Here is my code:[code]<?php$errmsg = "";$name = "";$email = "";$subject = "";$message = "";if(isset($_POST["send"])) { $name = trim($_POST["name"]); $email = trim($_POST["email"]); $subject = trim($_POST["subject"]); $message = trim($_POST["message"]); if ($name == "") { $errmsg = "Please enter your name"; } else if (!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $email)) { $errmsg = "Invalid email address"; } else if ($message == "") { $errmsg = "Please enter a message"; } if ($errmsg == "") { $to = "example@site.com"; mail($to, $subject, $message)?> <div style="margin-top:60px; text-align:center; height:160px"> <h1>Thank you for your message.</h1> <p><a href='#'>Return to Home page</a></p> </div> <?php }}if (!isset($_POST["send"]) || $errmsg != "") {?> <div id="error" class="contactFormError"><?=$errmsg;?></div> <table width="100%" style="margin-top:20px;"> <form id="contactform" name="contactForm" method="post"> <tr height="25px"> <td width="70px" align="right" ><h2 class="contactTitle">Name: </h2></td> <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td> </tr> <tr height="25px"> <td align="right"><h2 class="contactTitle">Email: </h2></td> <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td> </tr> <tr> <td> </td> </tr> <tr height="35px"> <td align="right"><h2 class="contactTitle">Subject: </h2></td> <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td> </tr> <tr> <td valign="top" align="right"><h2 class="contactTitle">Message: </h2></td> <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td> </tr> <tr height="35px"> <td> </td> <td><input type="submit" id="send" name="send" value="Send Message"></td> </tr> </form> </table> <?php}?>[/code]I've edited out all the unnecessary stuff from the HTML here and also simplified the php so that it's not getting anything wrong with validation or something. Still, I get no emails. I've tried different email addresses too. It's not in Junk either. Quote Link to comment Share on other sites More sharing options...
stef686 Posted September 14, 2006 Share Posted September 14, 2006 [quote]mail($to, $subject, £message)[/quote]"£" instead of "$"That might be something to do with it but I can't check it myself right now I'm afraid Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted September 14, 2006 Share Posted September 14, 2006 and maybe change example@site.com to your address? Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted September 14, 2006 Share Posted September 14, 2006 find:mail($to, $subject, £message)Replace with:mail($to, $subject, $message); Quote Link to comment Share on other sites More sharing options...
Mig Posted September 15, 2006 Author Share Posted September 15, 2006 No, sorry that was just a typo when I posted the code here. I changed it to be more simple so that I could make sure there were absolutely no errors with validation or concatenation or something. I've change the £ to a $ now.The email address I just changed just as an example. I have tried it with 3 real addresses, none of which receive email. Quote Link to comment Share on other sites More sharing options...
Mig Posted September 15, 2006 Author Share Posted September 15, 2006 Ok, I have simplified the code even more and still no emails. Surely there is nothing wrong with this code:[code]<?php$errmsg = "";$name = "";$email = "";$subject = "";$message = "";if(isset($_POST["send"])) { $name = $_POST["name"]; $subject = $_POST["subject"]; $message = $_POST["message"]; $to = "example@site.com"; mail($to, $subject, $message);} else {?> <table width="100%" style="margin-top:20px;"> <form id="contactform" name="contactForm" method="post"> <tr height="25px"> <td width="70px" align="right" ><h2 class="contactTitle">Name: </h2></td> <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td> </tr> <tr height="25px"> <td align="right"><h2 class="contactTitle">Email: </h2></td> <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td> </tr> <tr> <td> </td> </tr> <tr height="35px"> <td align="right"><h2 class="contactTitle">Subject: </h2></td> <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td> </tr> <tr> <td valign="top" align="right"><h2 class="contactTitle">Message: </h2></td> <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td> </tr> <tr height="35px"> <td> </td> <td><input type="submit" id="send" name="send" value="Send Message"></td> </tr> </form> </table> <?php}?> [/code] Quote Link to comment Share on other sites More sharing options...
stef686 Posted September 15, 2006 Share Posted September 15, 2006 [code]<form id="contactform" name="contactForm" method="post"> [/code]There is no "action" parameter telling the form to go anywhere when submitted to be processed. Simply put in the name of the file that you've shown us into the action parameter:[code]<form id="contactform" name="contactForm" action="contact.php" method="post"> [/code]For example, if the file is called contact.php Quote Link to comment Share on other sites More sharing options...
Mig Posted September 15, 2006 Author Share Posted September 15, 2006 But this code is from contact.php. It's not going anywhere..?Anyway I tried that but still no emails. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.