txapache Posted July 18, 2011 Share Posted July 18, 2011 Second Set of EYes, Hopefully this is it. I put in questions to hosting company with no response yet and now am asking yall (yes Texas), Please glanceat the form and processor and tell me if you see anything wrong. I test the contact form and get the Thank you message but never receive the email. Form: <form action="email_controller.php" method="post" enctype="text/plain" style="margin-top: 25px; margin-left: 20px;"> <table> <tr> <td>Name:</td> <td><input type="text" name="name" size="40" maxlength="100" ONCHANGE="var pattern=/[0-9]/; if(pattern.test(this.value))alert('Please enter a valid name')"></td> </tr><tr> <td>Company Name:</td> <td><input type="text" name="company" size="40" maxlength="100"></td> </tr><tr> <td>Website Address:</td> <td><input type="text" name="website" size="40" maxlength="100"></td> </tr><tr> <td>Email Address:</td> <td><input type="text" name="email" size="40" maxlength="100" ONCHANGE="var pattern=/[\s]/; if(pattern.test(this.value))alert('Please enter a valid email address')"></td> </tr><tr> <td>Phone Number:</td> <td><input type="text" name="phonenumber" size="15" maxlength="15"></td> </tr><tr> <td colspan="2">Comments:</td> </tr><tr> <td colspan="2" background="#d2b48c"><textarea name="comments" cols="50" rows="10"></textarea></td> </table> <input type="image" name="image" value="Submit" src="images/submitbutton.png" width="100" height="35" border="0" alt="Submit!"/> <input type="hidden" name="subject" value="Submission"/> <input type="hidden" name="redirect" value="index.php"/> <input type="hidden" name="form_order" value="alpha"/> <input type="hidden" name="form_delivery" value="hourly"/> <input type="hidden" name="form_format" value="html"/> </form> Processor: <?php ini_set("display_errors", "1"); error_reporting(-1); if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = 'me@mysite.com'; $email_subject = 'Contact Us'; $email_from = ($_POST['name']; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['company']) || !isset($_POST['website']) || !isset($_POST['email']) || !isset($_POST['phonenumber']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $firstname = $_POST['firstname']; // required $company = $_POST['company']; //not required $website = $_POST['website']; // not required $email = $_POST['email']; // required $phonenumber = $_POST['phonenumber']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Company: ".clean_string($company)."\n"; $email_message .= "Website: ".clean_string($website)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($phonenumber)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); header("Location: thankyou.html"); } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 18, 2011 Share Posted July 18, 2011 at a quick glance, it seems the email is being sent to 'me@mysite.com' as you've defined on line 8 and ignoring the email that's actually sent through the form. Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 19, 2011 Share Posted July 19, 2011 I don't see anything that is obviously wrong with the code. Remove the @ symbol before the mail call while you're debugging this, as that would suppress any errors. I'm assuming that what WebStyles pointed out is just something you changed before posting, and that you are using an actual email address. It is possible that your email is being sent, but that the email is in your spam folder. Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 Yes me@mysite was changed, on line 10 I added ")" to close the bracket and took at the @ symbol. At first I was just getting a white page but with those changes it now send me to the thankyou page as if the form was submitted, but I do not get the form in the email. I have checked the spam/junk folder also and nothing. No error messages displayed on page or error log. Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 19, 2011 Share Posted July 19, 2011 You don't get the form in the email, or you don't ever get the email at all? Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 I dont ever get the email at all Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 mail() function is sending to address in $email_to, but the one posted is stored in $email. Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 Not following I see the email_to address but I do not see where you are talking about the "email" stored address? Maybe my eyes are tired Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 you're grabbing the $_POST['email'] value into $email, but you're using $email_to when sending it. try changing: @mail($email_to, $email_subject, $email_message, $headers); to @mail($email, $email_subject, $email_message, $headers); Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 Unless it takes awhile to receive did that and nothing. Get the thank you screen but nothing in my inbox or bulk folder. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 have you tried just: $email = "youremail@yourdomain.com"; mail($email,"test","a little test"); just to be sure your server and smtp are set up correctly? Quote Link to comment Share on other sites More sharing options...
premiso Posted July 19, 2011 Share Posted July 19, 2011 Along with WebStyles (IE doing a simple email) I would check to see if the IP you are using to send email from is blacklisted. http://www.mxtoolbox.com/blacklists.aspx Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 19, 2011 Share Posted July 19, 2011 // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); header("Location: thankyou.html"); The value you supply in the "From:" header needs to be a valid email address. It also needs to be an email address that belongs to the server that is sending the mail. Some servers will NOT send mail if the from is not an address it owns (since that indicates you are trying to fake a message), and some servers will NOT accept mail if the from address does not belong to the server sending it (again, it appears to be an attempt to impersonate someone). You have set $email_from to the NAME entered by the user, which is likely not a valid email address. You are also setting the "Reply-To:" header to the user's name. This should be a valid email address as well. You should set this to the email address that the user entered. Your $email_to variable should be set (as it originally was) to the person you want to receive the message. Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 Ok new information, tried the test script but error need from. On to my test, I had the thank you html at the bottom of the email_controller.php and so when I submit form I would get the thankyou screen. I place the following code in the html section: <pre> <strong>DEBUG:</strong> <?php print_r($_POST); ?> </pre> and would get DEBUG array (). So nothing was being posted. I took the HTML part of the email_controller and placed it on its own page changed the header section to header('Location: thankyou.php'); Processed the form again and got a blank email_controller.php page. So for some reason when the form is filled out, none of the information is being ppicked up by the controller. Not sure why I figured the following script would grab the info $firstname = $_POST['firstname']; // required $company = $_POST['company']; //not required $website = $_POST['website']; // not required $email = $_POST['email']; // required $phonenumber = $_POST['phonenumber']; // not required $comments = $_POST['comments']; // required Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 19, 2011 Share Posted July 19, 2011 Have you done the simple test that WebStyles provided? This is the first thing you need to do. Some of the things that you say you are trying are pointless and irrelevant. One small incorrect detail will prevent the outbound email from being delivered. There are a lot of potential problems, and we need to eliminate them systematically, but we can't do that if you don't follow the instructions and advice of the people who are trying to help you debug this. Quote Link to comment Share on other sites More sharing options...
txapache Posted July 19, 2011 Author Share Posted July 19, 2011 Yes, I tried the simple test provided and received the error: Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\email_test.php on line 4 Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 19, 2011 Share Posted July 19, 2011 You are running this under XAMPP!!!!! I wish we had known this earlier. I don't use xampp but what I've read it apparently comes with an email server named Mercury SMTP. I'm not really sure it's worth trying to get something functional setup when you are not going to be using that as your productions server, however, here's a detailed how-to that describes how you might accomplish using it: http://www.danieltmurphy.com/setting-up-mercury-smtp/ There are intractible problems here like again the fact that email you send from this sort of setup will inevitably be seen as spam by any normal email provider you're using for testing, however, it may be enough in this case to give you verification you need while you test your code. For windows, settings in the php.ini that tell php where it can send email, need to be changed, so that php has a mailserver that can talk SMTP protocol, and will accept and forward email for you. So the other alternative is to set it to forward email to your local ISP that looks like it came from your normal workstation. Whether or not that is a feasible alternative pretty much depends on your ISP, and whether or not you can figure out what you need to do for the relevant settings in the php.ini. This is described a bit in the manual: http://us2.php.net/manual/en/mail.configuration.php#ini.smtp 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.