【发布时间】:2019-06-30 03:20:04
【问题描述】:
我已经在我的网站上使用 PHPMailer 大约 2 个月来向我的用户发送一封电子邮件,其中包含一些关于技术的信息和类似的东西。当用户访问网站并单击“获取我的月报”按钮时,会发送此电子邮件。电子邮件的内容只是正文上的一些文本和包含信息的 pdf 文件。一切工作正常,电子邮件发送没有问题,但今天有用户给我发了一封电子邮件,告诉我当他点击按钮时他没有收到他的电子邮件。当我检查 php mailsender 文件时,我收到此错误消息:
SMTP Error: data not accepted.
我使用 $mail->SMTPDebug = true 来获取错误的更多详细信息,这是我收到的消息的一部分:
//this is the first part of the message:
2019-06-30 02:29:11 SMTP INBOUND: "235 2.7.0 Authentication successful"
2019-06-30 02:29:11 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2019-06-30 02:29:11 CLIENT -> SERVER: MAIL FROM:<here is the same email of SMTP username>
2019-06-30 02:29:11 SMTP INBOUND: "250 2.1.0 Sender OK"
2019-06-30 02:29:11 SERVER -> CLIENT: 250 2.1.0 Sender OK
2019-06-30 02:29:11 CLIENT -> SERVER: RCPT TO:<here the email of the user>
2019-06-30 02:29:11 SMTP INBOUND: "250 2.1.5 Recipient OK"
2019-06-30 02:29:11 SERVER -> CLIENT: 250 2.1.5 Recipient OK
2019-06-30 02:29:11 CLIENT -> SERVER: DATA
2019-06-30 02:29:10 Connection: opening to smtp.office365.com:587, timeout=20, options=array()
2019-06-30 02:29:10 Connection: opened
//this is the part where show the error:
2019-06-30 02:29:12 SMTP INBOUND: "554 5.2.0 STOREDRV.Submission.Exception:InvalidLicenseException; Failed to process message due to a permanent exception with message Mailbox 'here the mailbox code' doesn't have a valid license. InvalidLicenseException: Mailbox 'here the mailbox code' doesn't have a valid license. [Hostname=here the host code]"
SMTP Error: data not accepted.
SMTP Error: data not accepted.
2019-06-30 02:29:12 CLIENT -> SERVER: QUIT
2019-06-30 02:29:12 SMTP INBOUND: "221 2.0.0 Service closing transmission channel"
2019-06-30 02:29:12 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2019-06-30 02:29:12 Connection: closed
这是我的 emailsender.php 文件,其中发送电子邮件的代码是:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
/* Exception class. */
require 'PHPMailer/src/Exception.php'; //PHPMailer
/* The main PHPMailer class. */
require 'PHPMailer/src/PHPMailer.php';
/* SMTP class, needed if you want to use SMTP. */
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(TRUE);
$mail->isSMTP();
$mail->Host= 'smtp.office365.com'; // (SMTP)
$mail->SMTPAuth= 'true';
$mail->Username= 'username email for SMTP';
$mail->Password= 'here the password of SMTP';
$mail->SMTPSecure= 'tls';
$mail->Port= '587';
$mail->SMTPDebug = true;
$mail->Timeout = 20;
$emailUsers = trim("usermail@mailserver.com", " ");
$message = "";
try {
/* Set the mail sender. */
$mail->setFrom("here the same email of USERNAME SMTP", "Admin");
$mail->addAddress($emailUsers);
/* Set the subject. */
$mail->Subject = 'Month Newspaper';
$mail->isHTML(TRUE);
/* Set the mail message body. */
$message = '<html>'.
'<head><title>Nivagastro Order Details</title></head>'.
'<body><h4 style="color: blue;"> Welcome to your Month Newspaper. UserAddress: '.utf8_decode('here the address of the user').' UserAuthWord: '.utf8_decode('This is the auth word of user').'!</h4>'.
'<hr style="margin-right: 100px;">'.
'<span>We will have new surprises for you the next month. More topics and news. Back soon!</span>'.
'</body>'.
'</html>';
$mail->Body = $message;
$mail->MsgHTML = $message;
$mail->AltBody = $message;
$mail->AddAttachment("files/NewspaperJun19.pdf"); // attachment
if(!$mail->send())
{
//echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "YOUR EMAIL HAS BEEN SEND SUCCESSFULY";
}
}
catch (Exception $e)
{
/* PHPMailer exception. */
echo $e->errorMessage();
}
catch (\Exception $e)
{
/* PHP exception (note the backslash to select the global namespace Exception class). */
echo $e->getMessage();
}
您是否知道为什么在昨天运行良好的情况下现在显示此错误?以及如何解决这个问题?
【问题讨论】:
-
这听起来像是那个用户的邮箱有问题,而不是你的代码。
标签: php pdf phpmailer html-email email-attachments