使用 PHPmailer 所有邮件都落入垃圾邮件文件夹

Using PHPmailer all mail landed in spam folder

我正在使用 smtp 身份验证,然后邮件也会进入垃圾邮件文件夹。 如果邮件正文包含外部文件 (file_get_containts),则邮件将进入垃圾邮件文件夹。

但是,如果邮件正文仅包含字符串,那么邮件将进入收件箱文件夹。

有人可以帮我解决这个问题吗?

这是我的代码:-

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

if( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['message']) ){

$name = $_POST['name'];

$email = $_POST['email'];

$phone = $_POST['phone'];
$m = nl2br($_POST['message']);

$mail   = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'mail.example.in';  
$mail->SMTPAuth = true;
$mail->Username = 'info@example.in';
$mail->Password = 'nsdfdk^^dsfx7wffdsry8e^';                           
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = 'info@example.in';
$mail->FromName = 'John Smith';
$mail->addCustomHeader('MIME-Version: 1.0');
$mail->addCustomHeader('Content-Type: text/html; charset=ISO-8859-1');
$mail->addAddress('example@gmail.com', 'Jay Senghani');

$mail->WordWrap = 50;                       

$mail->isHTML(true);     

$mail->Subject = "New Enquiry from  website";


$message = file_get_contents('emails/admin.html');
    $patterns = array();
    $patterns[0] = '/{name}/';
    $patterns[1] = '/{email}/';
    $patterns[2] = '/{number}/';
    $patterns[3] = '/{message}/';
    $replacements = array();
    $replacements[0] = $name;
    $replacements[1] = $email;
    $replacements[2] = $phone;
    $replacements[3] = $m;
$message = preg_replace($patterns, $replacements, $message);

$mail->Body = $message;


if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
        echo 'Message has been sent /n';
}

}

// For User Automated Email

if( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone'])){
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'mail.example.in'; 
$mail->SMTPAuth = true;                              
$mail->Username = 'info@example.in';
$mail->Password = 'ndfgk^dfgg^gfdggfdgdfgdfx7wfy8e^';                          
$mail->SMTPSecure = 'ssl';                     
$mail->Port = 465;
$mail->From = 'info@example.in';
$mail->FromName = 'John Smith';
$mail->addAddress($email, $name);    
$mail->addCustomHeader('MIME-Version: 1.0');
$mail->addCustomHeader('Content-Type: text/html; charset=ISO-8859-1');
$mail->isHTML(true);                                  

$mail->Subject = "Thank you for your interest Website ";
// $mail->addAttachment('Attachment Path', 'pdf'); 

$message = file_get_contents('emails/user.html');
$message = preg_replace('/{name}/', $name, $message);

$mail->Body = $message;

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent /n';
}

}


?>

这是我的管理模板:-

    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title></title>
      <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
      <div id="emailWrapper">
        <div id="emailHeader">
          <div class="topBar"></div>
          <a class="branding" href="http://example.com/" target="_blank" >
            <img src="https://i.imgur.com/JME5efdRs.png">
          </a>  
        </div> 
        <div id="emailContent">
          <h2 class="greetings">
            Dear Admin,
          </h2>
          <div class="content">
            <p class="intro">
              New enquiry from XYZ Website
            </p>
            <p>
              <strong>Name&nbsp;:</strong>&nbsp;{name}
            </p>
            <p>
              <strong>Number&nbsp;:</strong>&nbsp;{number}
            </p>
            <a class="email">
              <strong>Email&nbsp;:</strong>&nbsp;{email}
            </a>
            <p>
              <strong>Message&nbsp;:</strong>&nbsp;{message}
            </p>
          </div>
          <div class="regards">
            <h5><strong>Thanks &amp; Regards,</strong></h5>
            <h6>XyZ</h6>
          </div>
        </div>  <!-- END #emailContent  -->
        <div id="emailFooter">
          <div class="bottomBar">
            <p>
              &copy; 2018 Xyz. All rights reserved
            </p>
          </div>

        </div>  

      </div>  

    </body>
    </html>

电子邮件送达率故障排除很棘手,主要是因为缺乏有关主要电子邮件服务提供商(Gmail、Msn、mail.com、雅虎等)的反垃圾邮件功能内部工作原理的详细信息。良好的电子邮件送达率的主要方面通常是您的域声誉。如果您刚开始使用新的电子邮件域,大多数接收服务往往会对您的前 xx 封电子邮件持怀疑态度。 如果您的电子邮件包含无效或质量不佳的 html,它将提高垃圾邮件分数。加上附件肯定会加分。

我认为您没有附件的电子邮件刚好低于最终进入垃圾邮件文件夹的阈值。添加附件时,它会刚好高于相同的阈值。 大多数服务还适用于每个用户的规则,因此在同一服务中,收件人对您的电子邮件的处理可能会有所不同。

如果 PHPmailer 导致投递不畅,作为故障排除的一个步骤,我建议设置一个电子邮件客户端,如 Mozilla Thunderbird,并从那里发送一些电子邮件。 这将帮助您找出电子邮件送达率的来源。

如果您想避免考虑送达能力,您可以使用 Mailgun 等 SMTP 服务创建一个帐户。