我正在使用phpMailer使用PHP发送电子邮件。 邮件正在发送但收件箱/垃圾邮件或其他任何内容都没有收到。 令人惊讶的是它在几天前才开始工作。 我测试了它,发送和接收了近500-600封电子邮件。 但突然间它停止了工作"。
这是我的Php脚本:
public static function mailTo($recipients)
{
$f3 = \Base::instance();
$edit = $f3->get('editTrue');
$user = AclHelper::getCurrentUser();
$template= new \Template;
if(isset($edit))
{
$mailBody = $template->render('leave/requestEdit.html');
}
else
{
$mailBody= $template->render('leave/emailTemp.html');
}
// When true, PHPMailer returns exceptions
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->isHTML(true);
$mail->addAddress($user['email']);
$mail->addAddress("malakar.rakesh1993@gmail.com");
// foreach($recipients as $recipient){
// $mail->addCC($recipient);
// }
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = "malakar.rakesh1993@gmail.com";
$mail->Password = "abcd";
// $mail->Host = $f3->get('GBD.smtp.host'); // Specify main and backup SMTP servers
$mail->setFrom($user['email']);
$userFullName = trim(ucfirst($user['firstname'])) . " " . trim(ucfirst($user['lastname']));
$mail->FromName = $userFullName;
$mail->Body = $f3->get('message');
$mail->Body .="<br>". $mailBody;
if(isset($edit))
{
$mail->AltBody = '';
}
else
{
$mail->AltBody = 'Hello Team,<br>I would like to request leave for the leave dates specified as follows.
Application Date:' . $f3->get('issuedDate') . '<br>Leave requested from:' . $f3->get('leaveFrom') . '<br>Leave requested to:' . $f3->get('leaveTo') . '<br>Leave Description:' . $f3->get('leaveDescription') . 'Leave Type:' . $f3->get('leaveType').'<br><br>Hoping for a positive response.<br><br> Thank you.';
}
$mail->Subject = 'Updates on leave date applied';
$mailStatus = (boolean)$mail->send();
if ($mailStatus === true) {
return $mail;
}
} catch (phpmailerException $e) {
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
} catch (Exception $e) {
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
}
}
我收到了一封垃圾邮件,虽然[只有一封]说:
This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing
我无法弄清楚出了什么问题。
直到以前才开始工作。我的收件箱里收到了大量的电子邮件。
是否有发送电子邮件的限制?或者是否有人将其报告为垃圾邮件或欺骗?
非常感谢任何帮助。感谢。
答案 0 :(得分:1)
因为你正在使用SMTPSecure = 'ssl'
,所以你不会得到SMTPDebug = 2
的任何调试输出,因为它只显示SMTP级输出;您需要SMTPDebug = 3
来显示连接级别的问题。这可能是由PHP配置中的过期CA证书引起的。有很多关于这个的报告,因为gmail最近更改了它们(为什么你的脚本停止工作)。它包含在the troubleshooting guide中。
另外,为什么要在计划文本AltBody
中添加HTML标记?他们不会在那里工作。