2017-02-19 58 views
0

下午所有, 我把我的头发拉出来,只能是一个愚蠢的错误,但如此愚蠢,我不能追踪它。 我在使用Gmail的电子邮件中收不到任何联系表单。 目前我在此页面上测试http://www.theremotedoctor.co.uk/accbmw.html?scrollto=selection 并在此处出售右边的维珍芯片ID44 表格然后显示在屏幕上,客户完成&提交表格。 他们然后被带到我的感谢页面,但我从来没有收到电子邮件。通过Gmail和php文件接收电子邮件

这是我的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._%-][email protected][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

很有可能您的邮件被过滤为垃圾邮件。你必须检查你的http服务器错误日志文件。 – arkascha

+0

你用最小的测试邮件测试了邮件吗?你用@来抑制错误。如何检查错误并告诉我们。我总是使用https://github.com/PHPMailer/PHPMailer – mickmackusa

回答

0

尝试使用PHP mail function

您的代码将是这样的:

替换此:

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

与此:

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

在Gmail中创建过滤器来过滤所有以“DR CONTACT FORM”为主题的电子邮件将确保您的电子邮件不去垃圾邮件。

如何创建过滤器:

在Gmail中去设置>过滤器和阻止的地址>新建过滤器> 保留所有领域,除了主题留空,您必须添加DR联络表格 然后单击使用此搜索创建新过滤器(左下角),然后单击复选框,表示永不发送至垃圾邮件> 创建过滤器并且完成!

+0

abc很难让这个php作为即时通讯这样做的第三手。 你说垃圾邮件是我甚至在我的电子邮件中看到它或发送给我,但然后垃圾邮件? – user3169014

+0

发送给你,但Gmail放入垃圾邮件框..你尝试使用邮件()? –

+0

我将诚实的伴侣,这是所有新的给我,让无法但是遵循容易,这可能是 – user3169014