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



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

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

有人能帮我一下吗?

这是我的代码:-

<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
//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、Yahoo等(反垃圾邮件功能的内部工作细节。良好电子邮件传送的主要方面通常是您的域名声誉。如果你刚开始使用一个新的电子邮件域,大多数接收服务往往会对你的前xx封电子邮件持怀疑态度。如果你的电子邮件包含无效或糟糕的html,它将提高垃圾邮件的得分。如果你添加附件,肯定会提高分数。

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

作为排除PHPmailer是否对糟糕的交付负责的一步,我建议建立一个像Mozilla Thunderbird这样的电子邮件客户端,并从那里发送一些电子邮件。这将帮助你找出电子邮件可送达性的来源。

如果你想避免考虑可交付性,你可以使用Mailgun等SMTP服务建立一个帐户。

最新更新