Jump to content

Contact Form Success Msg, No Mail Arrives


Izzy-B

Recommended Posts

(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.   :sweat:
Link to comment
Share on other sites

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.). 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@ 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.