Izzy-B Posted August 11, 2016 Share Posted August 11, 2016 (Please, if one more person on an Internet forum cyber-yells at me or calls me an idiot today, I'm going to really start crying, so just know that, before we start. In fact, it's already too late; I'm already crying. Support forums make me nervous.) I have a simple contact form: <form action="send_form_email.php" method="post"> <div class="clear"> </div> <label>First Name:</label> <INPUT class="textbox left " type="text" name="first_name" value=""> <div class="clear"> </div> <label>Last Name:</label> <INPUT class="textbox left " type="text" name="last_name" value=""> <div class="clear"> </div> <label >E-Mail:</label> <INPUT class="textbox left" type="text" name="email" value=""> <div class="clear"> </div> <label >Phone Number:</label> <INPUT class="textbox left" type="text" name="telephone" value=""> <div class="clear"> </div> <label >Message:</label> <TEXTAREA class="textbox left" name="comments" ROWS="5" COLS="25"></TEXTAREA> <div class="clear"> </div> <INPUT class="pin" type="submit" name="submit" value="submit"> </form> This is my PHP form (send_form_email.php): <?php function isValidEmail($address) { if (filter_var($address, FILTER_VALIDATE_EMAIL) == FALSE) return false; /* explode out local and domain */ list($local, $domain) = explode('@', $address); $localLength = strlen($local); $domainLength = strlen($domain); return ( /* check for proper lengths */ ($localLength > 0 && $localLength < 65) && ($domainLength > 3 && $domainLength < 256) && (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A'))); } if (isset($_POST['email'])) { // E-Mail To: $email_to = "me@myexample.com"; $email_subject = "Site Form Feedback"; function died($error) { // your error code can go here echo "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['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('There appears to be a problem with the form you submitted.'); } $error_message = ""; if (!isValidEmail($_POST['email'])) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[a-z.'-]+$/i"; if (!preg_match($string_exp, $_POST['first_name'])) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if (!preg_match($string_exp, $_POST['last_name'])) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if (strlen($_POST['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 .= "First Name: " . clean_string($_POST['first_name']) . "\n"; $email_message .= "Last Name: " . clean_string($_POST['last_name']) . "\n"; $email_message .= "Email: " . clean_string($_POST['email']) . "\n"; $email_message .= "Telephone: " . clean_string($_POST['telephone']) . "\n"; $email_message .= "Comments: " . clean_string($_POST['comments']) . "\n"; // create email headers $headers = 'From: me@myexample.com' . "\r\n"; 'Reply-To: ' . $_POST['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting me. I will be in touch with you very soon. <?php } ?> I receive the success message "Thank you for contacting me, etc." upon clicking the submit button. The mail does not arrive in the inbox. It is not in the spam folder or in a queue. I talked to my server and they see no reason that mail is not arriving, barring some coding issue. Mail arrives in the inbox when sending directly from another email account; it only fails when being sent through the contact form. I would so appreciate any help; you just have no idea how much. Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/ Share on other sites More sharing options...
mac_gyver Posted August 11, 2016 Share Posted August 11, 2016 you need to test the value being returned by the mail() function. if it's a true value, it means that php was at least able to successfully hand the email off to a mail server (doesn't mean that mail server is going to do anything with it or that the receiving mail server will accept it.) if you get a false value, there should be a php error providing information as to why either php or the mail server isn't going to do anything with the email. you can get the last php error information using - error_get_last() (returns an array of information.). Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/#findComment-1535961 Share on other sites More sharing options...
Jacques1 Posted August 11, 2016 Share Posted August 11, 2016 The mail() function is archaic and known to cause trouble, because it relies on a local Sendmail program. If your server doesn't have that, or if you're not allowed to use it, or if the server isn't authorized to send e-mails directly, you're out of luck. Use a professional library like PHPMailer and relay the e-mails through the account which already worked. For example, if you're using Gmail, pass the Gmail SMTP server and your credentials to the library. Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/#findComment-1535962 Share on other sites More sharing options...
Izzy-B Posted August 11, 2016 Author Share Posted August 11, 2016 @ mac_gyver, thank you so much for replying. This is a third-party form and I apologize that I do not know coding. Would you please instruct where, in the form, I should place - error_get_last() in order to get the information? @ Jacques1, I showed the form to my server techs (Codero) but they didn't see anything that was a flag to them. However, I think coding is outside their normal scope of support. Can you explain what you mean when you suggest using a library? I at a disadvantage; I'm just a girl trying to get her web site going. I apologize for not knowing what this means. Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/#findComment-1535963 Share on other sites More sharing options...
Izzy-B Posted August 11, 2016 Author Share Posted August 11, 2016 We can close this (I'll try determine how to mark it resolved). I can clearly see, through exhaustive testing, that the fault must lie with the server, regardless. Thanks, anyway. Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/#findComment-1535978 Share on other sites More sharing options...
cyberRobot Posted August 18, 2016 Share Posted August 18, 2016 The topic has been marked solved. If you need anything else, you can start a new topic...or click the "Mark Unsolved" button in the lower-right corner of your post above. Quote Link to comment https://forums.phpfreaks.com/topic/301842-contact-form-success-msg-no-mail-arrives/#findComment-1536315 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.