0

Afternoon all, I am pulling my hair out over something that can only be a silly mistake but so silly i cant track it down. I receive no contact forms in my email of which i use Gmail. At present i am testing it on this page here http://www.theremotedoctor.co.uk/accbmw.html?scrollto=selection And on this item for sale on the right Virgin Chip ID44 Form is then shown on screen,customer completes & submits form. They are then taken to my thank-you page BUT i never receive email.

Here is my php code.

<?php

if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "*********gmail.com";
    $email_subject = "DR CONTACT FORM";

    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['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['post_code']) ||
        !isset($_POST['delivery_destination']) ||
        !isset($_POST['paypal_email']) ||
        !isset($_POST['part_number']) ||
        !isset($_POST['image_address']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = strtoupper($_POST['first_name']); // required
    $last_name = strtoupper($_POST['last_name']); // required
    $email_from = $_POST['email']; // required
    $telephone = strtoupper($_POST['telephone']); // not required
    $post_code = strtoupper($_POST['post_code']); //not required
    $delivery_destination = strtoupper($_POST['delivery_destination']); // required
    $paypal_email = $_POST['paypal_email']; //required
    $part_number = strtoupper($_POST['part_number']); //hidden
    $image_address = $_POST['image_address']; //hidden
    $comments = strtoupper($_POST['comments']); // required
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br>';
  }
  if(!preg_match($email_exp,$paypal_email)) {
    $error_message .= 'The Paypal Email Address you entered does not appear to be valid.<br>';
  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br>';
  }

  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last 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 .= '<html><body>';  
    $email_message .= '<table rules="all"  border="1"  cellpadding="10" style="width: 560px; margin: auto; border-collapse: collapse;">';
    $email_message .= '<tr><th colspan="2">FORM DETAILS</th</tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>FIRST NAME:</b> </td><td><b>' . clean_string($first_name) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>LAST NAME:</b> </td><td><b>' . clean_string($last_name) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>EMAIL:</b></td><td><b>' . clean_string($email_from) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>TELEPHONE:</b></td><td><b>' . clean_string($telephone) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>POST CODE:</b></td><td><b>' . clean_string($post_code) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>DELIVERY DESTINATION:</b></td><td><b>' . clean_string($delivery_destination) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>PAYPAL EMAIL:</b></td><td><b>' . clean_string($paypal_email) . '<b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>PART NUMBER:</b></td><td><b>' . clean_string($part_number) . '</b></td></tr>';
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>IMAGE ADDRESS FOR:</b></td><td><b><a href="' . $image_address . '" >' . clean_string($part_number) . ' IMAGE</a></b></td></tr>';    
    $email_message .= '<tr><td style="background-color: #eeeeee"><b>COMMENTS:</b></td><td><b>' . clean_string($comments) . '</b></td></tr>';        
    $email_message .= '</table>';  
    $email_message .= '</body></html>'; 

   // create email headers
   $headers = 'From: '.$email_from."\n".
   'Reply-To: '.$email_from."\n" .
   'X-Mailer: PHP/' . phpversion();
   $headers .= "MIME-Version: 1.0\n";
   $headers .= "Content-Type: text/html; charset=ISO-8859-1\n";//ISO-8859-1

   @mail($email_to, $email_subject, $email_message, $headers); 

   header('Location: http://www.theremotedoctor.co.uk/thank_you_page.html'); 
?>


<?php
}
?>

Please can you advise if you see anything wrong. Many Thanks.

HPierce
  • 6,211
  • 5
  • 32
  • 43
  • 1
    Most likely your messages are filtered as SPAM. You'd have to check your http servers error log file. – arkascha Feb 19 '17 at 15:11
  • Have you tested the mailer with a minimal test email? You are suppressing errors with @. How about checking for an error and letting us know. I always use https://github.com/PHPMailer/PHPMailer – mickmackusa Feb 19 '17 at 15:14

1 Answers1

0

Try using PHP mail function

Your code will look like this:

replace this:

@mail($email_to, $email_subject, $email_message, $headers); 

with this:

mail($email_to, $email_subject, $email_message, $headers);

In gmail create a filter to filter all emails with the subject "DR CONTACT FORM" that will ensure that your email doesn't go to spam.

How to create filters:

In gmail go to settings > Filters and Blocked Addresses > Create new filter > leave all fields blank except for subject which you must add DR CONTACT FORM then click create new filter with this search (bottom left corner) and then click check box that says never send to spam > create filter and you're done!

Coffee coder
  • 132
  • 1
  • 1
  • 9