我正在使用 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 = '[email protected]';
$mail->Password = 'nsdfdk^^dsfx7wffdsry8e^';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = '[email protected]';
$mail->FromName = 'John Smith';
$mail->addCustomHeader('MIME-Version: 1.0');
$mail->addCustomHeader('Content-Type: text/html; charset=ISO-8859-1');
$mail->addAddress('[email protected]', '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 = '[email protected]';
$mail->Password = 'ndfgk^dfgg^gfdggfdgdfgdfx7wfy8e^';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = '[email protected]';
$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 :</strong> {name}
</p>
<p>
<strong>Number :</strong> {number}
</p>
<a class="email">
<strong>Email :</strong> {email}
</a>
<p>
<strong>Message :</strong> {message}
</p>
</div>
<div class="regards">
<h5><strong>Thanks & Regards,</strong></h5>
<h6>XyZ</h6>
</div>
</div> <!-- END #emailContent -->
<div id="emailFooter">
<div class="bottomBar">
<p>
© 2018 Xyz. All rights reserved
</p>
</div>
</div>
</div>
</body>
</html>
解决电子邮件送达问题非常棘手,主要是因为缺乏主要电子邮件服务提供商(Gmail、Msn、mail.com、Yahoo 等)反垃圾邮件功能内部运作的详细信息。良好的电子邮件送达率的主要方面通常是您的域名声誉。如果您刚刚开始使用新的电子邮件域,大多数接收服务往往会对您的前 xx 封电子邮件持怀疑态度。 如果您的电子邮件包含无效或不良的 html,则会提高垃圾邮件分数。如果你添加附件肯定会提高分数。
我认为您没有附件的电子邮件刚刚低于进入垃圾邮件文件夹的阈值。添加附件时,它会略高于相同的阈值。 大多数服务还适用每用户规则,因此同一服务中的不同收件人可以对电子邮件进行不同的处理。
作为排除 PHPmailer 是否导致投递不佳的原因的一个步骤,我建议设置一个电子邮件客户端(例如 Mozilla Thunderbird)并从那里发送一些电子邮件。 这将帮助您找出电子邮件送达率的来源。
如果您想避免考虑送达能力,您可以使用 Mailgun 等 SMTP 服务启动帐户。