Chinx Posted March 23, 2009 Share Posted March 23, 2009 Hi, I'm new to PHP and this forum. I'd appreciate help on correcting my contact form... I read through a few threads but couldn't understand where I needed to modify my code as they were customized. I have two files. One called contact.php (with design and fields) the other contact_code.php (with php code) Following code is on the design page: <form method="post" action="contact_code.php"> <table align=left> <tr> <td width="362" class="contact-text"></td> <td width="20"></td> </tr> <tr> <td class="contact-text">Your Name</td></tr> <td><input size=45 name="fName"></td> </tr> <tr> <td class="contact-text">Email:</td></tr> <td><input size=45 name="Email"></td> </tr> <tr> <td class="contact-text">Phone:</td></tr> <td><input size=25 name="Phone"></td> </tr> <tr> <td colspan=2 class="contact-text">Message:</td></tr> <tr><td colspan=2 align=left> <textarea name="Message" rows=7 cols=45></textarea></td> </tr> <tr> <td colspan=2 align=left> <input type=submit name="send" value="Submit"></td> </tr> </table> </form> ---------- Following code is on the code page: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $fname = $_REQUEST['fName'] ; $headers = "From: $Email"; $subject = "A message through invoridesign.com"; $fields = array(); $fields{"fName"} = "fName"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Message"} = "Message"; $body = "We have received the following information: "; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s ",$b,$_REQUEST[$a]); } $headers2 = "From: [email protected]"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us"; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($fname == '') {print "You have not entered a first name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.invirodesign.com" );} else {print "We encountered an error sending your mail, please notify [email protected]"; } } } ?> When I post these pages online and check the form by sending myself an email, I get the following error: We encountered an error sending your mail, please notify [email protected] Thank you[/] Link to comment https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/ Share on other sites More sharing options...
WolfRage Posted March 23, 2009 Share Posted March 23, 2009 Well obviously from the logic of your script the mail() function is failing. So why is it failing? Do you have error reporting turned on? <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> Link to comment https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/#findComment-791422 Share on other sites More sharing options...
shadiadiph Posted March 23, 2009 Share Posted March 23, 2009 firstly your email is Email in your form and email in your script secondly looks like you are trying to send via sendmail through php this probably will not work need to use an address that belongs to you like info@invirodesign Thirdly you can try this might work for you although in the header i have no idea what to put so iput what you put usually i would use header ( "location: thankyou.php" ); . And make a thankyou page but you could just try this with your html form it should work $email = ($_POST["Email"]; $fname = ($_POST["fName"]; $message = ($_POST["message"]; if ($Email=="") { print "You have not entered an email, please go back and try again"; } if ($fName="") { print "You have not entered an email, please go back and try again"; } header("Location: thankyou.php"); $to = "$email"; $subject = "Thank you for contacting us"; $MsgHeader = "From: Inviro Design <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>HTML message</title> </head> <body> <table> <tr><td>$fName thank you for contacting us</td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); $to = "[email protected]"; $subject = "Thank you for contacting us"; $MsgHeader = "From: Inviro Design <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>HTML message</title> </head> <body> <table> <tr><td>$fName has sent you the following message:</td></tr> <tr><td>$message</td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); exit; I can't see sendto in your form so i removed it, it doesn't seem to serve any purpose Link to comment https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/#findComment-791586 Share on other sites More sharing options...
Chinx Posted March 27, 2009 Author Share Posted March 27, 2009 Sorry, It isn't working. I actually have two php files. Not an html. So would I create a new thankyou html and paste your last mentioned code in it? Thank you Link to comment https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/#findComment-794835 Share on other sites More sharing options...
shadiadiph Posted March 28, 2009 Share Posted March 28, 2009 yes but if you use the code above and want to name the thankyou as thankyou.html please change the line above from header("Location: thankyou.php"); to header("Location: thankyou.html"); also make sure you have [email protected] set up Link to comment https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/#findComment-795922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.