通过Gmail& php文件

时间:2017-02-19 14:59:50

标签: php email

下午所有, 我把头发拉过来只能是一个愚蠢的错误,但很傻,我无法追踪它。 我在使用Gmail的电子邮件中没有收到任何联系表单。 目前我正在此页面上对其进行测试http://www.theremotedoctor.co.uk/accbmw.html?scrollto=selection 在这个项目上出售右侧Virgin Chip ID44 然后在屏幕上显示表格,客户完成&提交表格。 然后他们被带到我的感谢页面但我从未收到过电子邮件。

这是我的PHP代码。

<?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
}
?>

如果您发现任何错误,请告诉我。 非常感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用PHP mail function

您的代码如下所示:

替换这个:

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

用这个:

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

在gmail中创建一个过滤器,用于过滤所有包含主题的电子邮件&#34; DR CONTACT FORM&#34;这将确保您的电子邮件不会发送垃圾邮件。

如何创建过滤器:

在gmail中转到设置&gt; <滤波器和阻塞地址>创建新过滤器&gt; 将所有字段留空,但必须添加 DR CONTACT FORM 的主题除外 然后单击使用此搜索创建新过滤器(左下角),然后单击“永不发送到垃圾邮件”复选框&gt; 创建过滤器,然后完成!