如何避免PHP邮件输出到垃圾邮件?

时间:2016-03-16 14:55:39

标签: php email phpmailer

我使用php mail()的邮件将转到垃圾邮件文件夹 - 为什么?

<?php
    ob_start();
    session_start();

    //define the receiver of the email
    $from='mrashidap@gmail.com';
    $to = 'mrashidap@gmail.com';
    //define the subject of the email
    $subject = 'inform me please, when u receive this mail'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \r\n
    #Now We Can Use HTML Tags

    $headers = "From: " . strip_tags($from). "\r\n";
    $headers .= "Organization: appstribes\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= "Reply-To: ".($from) . "\r\n";
    $headers .= "Return-Path: ".($from) . "\r\n";
    $headers .= "X-Priority:3 \r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
     $headers .= "X-MSMail-Priority: high\r\n";

    $msg = '<html><body>';
    $msg .= '<p>Dear Sir/Madam</p><br/>';
    $msg .= '<p><strong>GOOD DAY..!!!</strong></p>';
    $msg .= '<p>Thank you for contacting Keita Customer Service. We regret any inconvenience you have experienced. Your request has been received, and a ticket has been created for you with,</p>';
    $msg .= '<p><strong>Reference ID : khd004</strong></p>';
    $msg .= '<p>Our team is looking into your request and you can expect next to be contacted with either an answer to your question(s) or a solution to the issue(s) raised. Our expected time-frames to respond will vary according to the severity or complexity of the matter being addressed and volume of contacts reaching us. However we assure you that we are working to get back to you as fast as possible and to properly address your questions and concern.</p>';
    $msg .= '<p>Regards,</p>';

    $msg .= '<p>Keita IT Team</p><br/>';

    $msg .= '</body></html>';
    $message=$msg;

    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

大多数邮件都是垃圾邮件。但是发送到Gmail的邮件正在收件箱中。

1 个答案:

答案 0 :(得分:0)

  1. 您的脚本声称此电子邮件是从gmail发送的,这不是真的
  2. 不清楚您的服务器是否使用DKIM签署电子邮件,是否有SPF
  3. 服务器可以是灰名单
  4. Google可能不会将您的域名指定为允许的发件人
  5. 任何这些原因都可能导致您将电子邮件视为垃圾邮件。