virtualscouser Posted December 5, 2008 Share Posted December 5, 2008 I have a form that I created for one of my clients that works peachy. I copied and pasted all the code from the form (along with the PHP) and did some modifications to it for another client.(why mess with a good thing right?) When I click the submit button no email is sent. I get the "Thanks for submitting your information" page and when I leave out the required fields, PHP does it's job and tells me that I'm missing them. The hosting company uploaded a phpmail file and that works fine.(sends the email no problem) So I' really lost why this form isn't working. Here's the code: <?php if (isset($_POST['submit'])) { // handle the form. //Check for first name. if (strlen($_POST['first_name']) > 0) { $first_name = TRUE; } else { $first_name = FALSE; echo '<p>You forgot to enter your first name!</p>'; } //Check for last name. if (strlen($_POST['last_name']) > 0) { $last_name = TRUE; } else { $last_name = FALSE; echo '<p>You forgot to enter your last name!</p>'; } //Check for email. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; echo '<p>You forgot to enter your e-mail address!</p>'; } if ($first_name && $last_name && $email) { //If everything's ok. // Good to go. $to = "My Email goes here"; $subject = "Information Request"; $message .= "First Name:\t".$_REQUEST["first_name"]."\n"; $message .= "Last Name:\t".$_REQUEST["last_name"]."\n"; $message .= "Phone Number:\t".$_REQUEST["phone"]."\n"; $message .= "Email:\t".$_REQUEST["email"]."\n"; $message .= "How did you find us?:\t".$_REQUEST["refered"]."\n"; $message .= "Comments:\t".$_REQUEST["comments"]."\n"; $from = "$email"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>'; } else { // not ok. echo '<p>Please go back and insert the required information.</p>'; } } else { // Display the form. ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <table width="500" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td> </tr> <tr> <td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td> <td width="300"><input name="first_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5"><span class="style17">*</span>Last Name:</span></td> <td><input name="last_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Phone Number :</span></td> <td><input name="phone" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">*Email:</span></td> <td><input name="email" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">How did you find us?:</span></td> <td><input name="refered" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Comments:</span></td> <td><textarea name="comments" cols="40" rows="3"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td> </tr> </table> </form> <!-- End of the form --> <?php } ?></p> Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 check what error you're getting, see if it thinks its sending if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 5, 2008 Author Share Posted December 5, 2008 check what error you're getting, see if it thinks its sending if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; That's the thing, I'm not getting any errors, it comes back with the message thanking me for submitting my information like everything is fine. I just never receive the email. Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 The way your code is laid out, you're not checking if the mail() function returns true. Put my little bit of code in place of yours and let me know what it says change; mail($to,$subject,$message,$headers); echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>'; to if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 5, 2008 Author Share Posted December 5, 2008 Nope, your code crashes the page. Gives me a HTTP500 error when submit is clicked. The way your code is laid out, you're not checking if the mail() function returns true. Put my little bit of code in place of yours and let me know what it says change; mail($to,$subject,$message,$headers); echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>'; to if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 Post your code, with mine in place Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 5, 2008 Author Share Posted December 5, 2008 Post your code, with mine in place <?php if (isset($_POST['submit'])) { // handle the form. //Check for first name. if (strlen($_POST['first_name']) > 0) { $first_name = TRUE; } else { $first_name = FALSE; echo '<p>You forgot to enter your first name!</p>'; } //Check for last name. if (strlen($_POST['last_name']) > 0) { $last_name = TRUE; } else { $last_name = FALSE; echo '<p>You forgot to enter your last name!</p>'; } //Check for email. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; echo '<p>You forgot to enter your e-mail address!</p>'; } if ($first_name && $last_name && $email) { //If everything's ok. // Good to go. $to = "MyEmail Here"; $subject = "Information Request"; $message .= "First Name:\t".$_REQUEST["first_name"]."\n"; $message .= "Last Name:\t".$_REQUEST["last_name"]."\n"; $message .= "Phone Number:\t".$_REQUEST["phone"]."\n"; $message .= "Email:\t".$_REQUEST["email"]."\n"; $message .= "How did you find us?:\t".$_REQUEST["refered"]."\n"; $message .= "Comments:\t".$_REQUEST["comments"]."\n"; $from = "$email"; $headers = "From: $from"; if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; } else { // Display the form. ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <table width="500" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td> </tr> <tr> <td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td> <td width="300"><input name="first_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5"><span class="style17">*</span>Last Name:</span></td> <td><input name="last_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Phone Number :</span></td> <td><input name="phone" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">*Email:</span></td> <td><input name="email" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">How did you find us?:</span></td> <td><input name="refered" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Comments:</span></td> <td><textarea name="comments" cols="40" rows="3"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td> </tr> </table> </form> <!-- End of the form --> <?php } ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 Try this, and don't forget to put your email address in <?php if (isset($_POST['submit'])) { // handle the form. //Check for first name. if (strlen($_POST['first_name']) > 0) { $first_name = TRUE; } else { $first_name = FALSE; echo '<p>You forgot to enter your first name!</p>'; } //Check for last name. if (strlen($_POST['last_name']) > 0) { $last_name = TRUE; } else { $last_name = FALSE; echo '<p>You forgot to enter your last name!</p>'; } //Check for email. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; echo '<p>You forgot to enter your e-mail address!</p>'; } if ($first_name && $last_name && $email) { //If everything's ok. // Good to go. $to = "MyEmail Here"; $subject = "Information Request"; $message = "First Name:\t".$_REQUEST['first_name']."\n"; $message .= "Last Name:\t".$_REQUEST['last_name']."\n"; $message .= "Phone Number:\t".$_REQUEST['phone']."\n"; $message .= "Email:\t".$_REQUEST['email']."\n"; $message .= "How did you find us?:\t".$_REQUEST['refered']."\n"; $message .= "Comments:\t".$_REQUEST['comments']."\n"; $from = "$email"; $headers = "From: $from"; if(mail($to,$subject,$message,$headers)) echo 'all good'; else echo 'not sent'; } else { // Display the form. ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <table width="500" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td> </tr> <tr> <td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td> <td width="300"><input name="first_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5"><span class="style17">*</span>Last Name:</span></td> <td><input name="last_name" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Phone Number :</span></td> <td><input name="phone" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">*Email:</span></td> <td><input name="email" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">How did you find us?:</span></td> <td><input name="refered" type="text" size="40" /></td> </tr> <tr> <td><span class="style5">Comments:</span></td> <td><textarea name="comments" cols="40" rows="3"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td> </tr> </table> </form> <!-- End of the form --> <?php } ?> Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 5, 2008 Author Share Posted December 5, 2008 Wow, now I'm getting a straight HTTP 500 Error http://www.force1steelhomes.com/contact/copy_of_contact.php is the page. Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 Well, I'm not getting an error, I get a blank page?? Also there shouldn't be a problem with your code, it all looks fine so my appologise Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 5, 2008 Author Share Posted December 5, 2008 I restored my old one on that page. The only code you changed was that small bit right? The only thing that pops in my head is the missing '{}" brackets. Quote Link to comment Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 Just copy and paste ur original code back. Quote Link to comment Share on other sites More sharing options...
virtualscouser Posted December 8, 2008 Author Share Posted December 8, 2008 Anybody else want to take a stab at this? What is really winding me up about it is that the hosting company sent me a simple php program that works just fine, I receive the sample mail it sends without issue so I know the server is sending the mail but for some reason it doesn't want to process my script. ??? The validation works but it just won't send the email. Thanks! 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.