pensyd Posted August 29, 2010 Share Posted August 29, 2010 Hi Guys, I am sure you will laugh at my coding attempt, but i need your help. I have set up a contact form and a PHP process to send the email. Everything appears to be working except the sending part. All fields validate as they should, the form forward to a thank you page as it should. But no emails are received either at my domain end or from the sender i am testing with. Here is my form code: <form id="form1" name="form1" method="post" action="emailform.php" onsubmit="window.setTimeout(function(){window.location='/thankyou.html'},20); return true;"> <p><span id="sprytextfield1"> <label for="name">Name: </label> <input name="name" type="text" id="name" tabindex="10" /> <span class="textfieldRequiredMsg">Your name is required.</span><span class="textfieldMaxCharsMsg">No more than 50 characters in your Name.</span><span class="textfieldMinCharsMsg">Your Name must be atleast 4 characters long.</span></span></p> <p><span id="sprytextfield2"> <label for="email">Email: </label> <input type="text" name="email" id="email" tabindex="20" /> <span class="textfieldRequiredMsg">An Email Address is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p><span id="spryselect1"> <label for="state">State</label> <select name="state" id="state" tabindex="30"> <option>ACT</option> <option>NSW</option> <option>Queensland</option> <option>Victoria</option> <option>Tas</option> <option>SA</option> <option>WA</option> <option>NT</option> </select> <span class="selectInvalidMsg">Please select a valid State.</span></span></p> <p>What styles are you interested in doing? <label for="styles"></label> <select name="styles" id="styles" tabindex="40"> <option>Portraits</option> <option>Fashion</option> <option>Swimwear</option> <option>Lingerie</option> <option>Art Nude</option> <option>All Styles Possible</option> <option>Just Curious for Now</option> </select> </p> <p>Please leave any Message or Comments Below:</p> <p><span id="sprytextarea1"> <label for="comments"></label> <textarea name="comments" id="comments" cols="45" rows="5" tabindex="50"></textarea> <span class="textareaRequiredMsg">Please enter your comments here.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Send Form" tabindex="50" /> </p> </form> Here is the PHP Code: <?php /* Subject and variables */ $emailSubject = 'New Email Enquiry'; $webMaster = '[email protected]'; /* Gathering data variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $stateField = $_POST['state']; $stylesField = $_POST['styles']; $commentsField = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> State: $state <br> Style: $style <br> Comment: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); ?> Any help you can offer would be greatly appreciated. I am not looking for anything over the top, just something simple that works. Thanks David Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/ Share on other sites More sharing options...
Birdmansplace Posted August 29, 2010 Share Posted August 29, 2010 I use pear and its email packages. Best move i made. I can see anything off hand thats causing it. try changing to this $HTTP_POST_VARS and not just post and see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104835 Share on other sites More sharing options...
pensyd Posted August 29, 2010 Author Share Posted August 29, 2010 Thanks, Just made that change, but still no go. Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104836 Share on other sites More sharing options...
Birdmansplace Posted August 29, 2010 Share Posted August 29, 2010 add this inside you php tags to find errors ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104837 Share on other sites More sharing options...
PaulRyan Posted August 29, 2010 Share Posted August 29, 2010 Hey Pensyd, I think I know what why your script is not working. I think the onSubmit function does not allow the form to actually post to the file you want. Firstly change this <form id="form1" name="form1" method="post" action="emailform.php" onsubmit="window.setTimeout(function(){window.location='/thankyou.html'},20); return true;"> To this <form id="form1" name="form1" method="post" action="emailform.php"> The use the following PHP code instead of your own <?php /* Subject and variables */ $emailSubject = 'New Email Enquiry'; $webMaster = '[email protected]'; /* Gathering data variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $stateField = $_POST['state']; $stylesField = $_POST['styles']; $commentsField = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> State: $state <br> Style: $style <br> Comment: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); if($sucess) { header("Location: /thankyou.html"); } else { echo 'Put a nice error message here or redirect back to the form.'; } ?> Thanks, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104838 Share on other sites More sharing options...
pensyd Posted August 29, 2010 Author Share Posted August 29, 2010 Hi Guys, Paul, i made the changes you suggested and it came up with the error message. So i put in the error report as suggested and got this reply, Notice: Undefined variable: name in /home/davidsp3/public_html/emailform.php on line 18 Notice: Undefined variable: email in /home/davidsp3/public_html/emailform.php on line 19 Notice: Undefined variable: state in /home/davidsp3/public_html/emailform.php on line 20 Notice: Undefined variable: style in /home/davidsp3/public_html/emailform.php on line 21 Notice: Undefined variable: comments in /home/davidsp3/public_html/emailform.php on line 21 Notice: Undefined variable: email in /home/davidsp3/public_html/emailform.php on line 24 Notice: Undefined variable: sucess in /home/davidsp3/public_html/emailform.php on line 28 The Form did not process properly, please go back and try again Looks like its not liking the variable names in the script. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104865 Share on other sites More sharing options...
pensyd Posted August 29, 2010 Author Share Posted August 29, 2010 These are the actual line numbers Name: $name <br> Line 17 Email: $email <br> Line 18 State: $state <br> Line 19 Style: $style <br> Line 20 Comment: $comments <br> Line 21 $headers = "From: $email\r\n"; Line 24 $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); if($sucess) { Line 28 header("Location: /thankyou.html"); } else { echo 'The Form did not process properly, please go back and try again'; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104867 Share on other sites More sharing options...
DavidAM Posted August 29, 2010 Share Posted August 29, 2010 Apparently there are some typos in your original code. You retrieve the POST fields into variables, BUT then use different names for the variables in the form: /* Gathering data variables */ $nameField = $_POST['name']; // YOU CALLED THIS $name IN THE CODE BELOW $emailField = $_POST['email']; // YOU CALLED THIS $email IN THE CODE BELOW $stateField = $_POST['state']; // YOU CALLED THIS $state IN THE CODE BELOW $stylesField = $_POST['styles']; // YOU CALLED THIS $style IN THE CODE BELOW $commentsField = $_POST['comments']; // YOU CALLED THIS $comments IN THE CODE BELOW $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> State: $state <br> Style: $style <br> Comment: $comments <br> EOD; There's also a missing "c" in the second $success reference. Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104889 Share on other sites More sharing options...
pensyd Posted August 29, 2010 Author Share Posted August 29, 2010 Thanks DavidAM and everyone else for you help. It is working now. I greatly appreciate your help. I have just one more question sorry. If i want to send and email to the person who filled out the form, with a small message in the subject line. What should i put in the code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211997-contact-form-not-working/#findComment-1104962 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.