PHP 发送数据错误的邮件程序未被接受
PHP Mailer sending an error of data not accepted
我在 PHPMailer 中遇到以下错误:
SMTP Error: data not accepted.SMTP server error: DATA END command
failed Detail:
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message
Cannot submit message.
我正在使用以下内容:
public function sendEmail($conn, $user, $to_email, $subject, $messageToSent)
{
//Check if user exists
$exist = $this->checkIfUserExist($conn, $user);
$from = $this->getUserEmail($conn, $user);
if($exist['exist'])
{
// Please specify your Mail Server - Example: mail.example.com.
//$mail = new PHPMailer\PHPMailer();
$mail = new PHPMailer\PHPMailer\PHPMailer; // Passing `true` enables exceptions
$message = "success";
try {
//Server settings
$mail->SMTPDebug = 2; // set it to 2 to Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
if($from=='' || $from==null || $from=="NULL")
{
$mail->setFrom('i@abc.org');
}
if($from!='')
{
$mail->setFrom($from);
}
$mail->Username = 'i@abc.org'; // SMTP username
$mail->Password = 'xyz'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//$mail->AuthType = 'PLAIN';
//Recipients
//$mail->setFrom($user.'@abc.com');
//$mail->setFrom($from);
$mail->addAddress('i@abc.org'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', $subject);
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
if($from=="i@abc.org")
{
$mail->Body = $messageToSent. '<p>The user asking for password recovery does not have a valid email. Thus, the sender will be shown as sent from the admin email. The user have the following ID: </p><h3>'.$exist['user_id'].'</h3>';
}
else
{
$mail->Body = $messageToSent. '<p>The user have the following ID: </p><h3>'.$exist['user_id'].'</h3>';
}
$mail->AltBody = 'Please take actions according to needs.';
if($mail->send())
{
echo json_encode($message);
}
else
{
echo json_encode($mail->ErrorInfo);
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
else
{
echo json_encode("UserDoesntExist");
}
}
我看过here$mail->Username
和$mail->setFrom
应该是一样的,但是这样一来,我们应该得到每封邮件的密码来更改$mail->Password
.
线索在异常的名称中:SendAsDenied
;它是说您不能使用除您的用户名以外的任何其他地址作为发件人地址,尤其是不能使用任意(伪造)地址。
如果您想避免伪造问题,请从您的管理员地址发送,但将用户地址设置为回复地址。这样你就不会伪造,回复就会到正确的地方。
我在 PHPMailer 中遇到以下错误:
SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.
我正在使用以下内容:
public function sendEmail($conn, $user, $to_email, $subject, $messageToSent)
{
//Check if user exists
$exist = $this->checkIfUserExist($conn, $user);
$from = $this->getUserEmail($conn, $user);
if($exist['exist'])
{
// Please specify your Mail Server - Example: mail.example.com.
//$mail = new PHPMailer\PHPMailer();
$mail = new PHPMailer\PHPMailer\PHPMailer; // Passing `true` enables exceptions
$message = "success";
try {
//Server settings
$mail->SMTPDebug = 2; // set it to 2 to Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
if($from=='' || $from==null || $from=="NULL")
{
$mail->setFrom('i@abc.org');
}
if($from!='')
{
$mail->setFrom($from);
}
$mail->Username = 'i@abc.org'; // SMTP username
$mail->Password = 'xyz'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//$mail->AuthType = 'PLAIN';
//Recipients
//$mail->setFrom($user.'@abc.com');
//$mail->setFrom($from);
$mail->addAddress('i@abc.org'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', $subject);
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
if($from=="i@abc.org")
{
$mail->Body = $messageToSent. '<p>The user asking for password recovery does not have a valid email. Thus, the sender will be shown as sent from the admin email. The user have the following ID: </p><h3>'.$exist['user_id'].'</h3>';
}
else
{
$mail->Body = $messageToSent. '<p>The user have the following ID: </p><h3>'.$exist['user_id'].'</h3>';
}
$mail->AltBody = 'Please take actions according to needs.';
if($mail->send())
{
echo json_encode($message);
}
else
{
echo json_encode($mail->ErrorInfo);
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
else
{
echo json_encode("UserDoesntExist");
}
}
我看过here$mail->Username
和$mail->setFrom
应该是一样的,但是这样一来,我们应该得到每封邮件的密码来更改$mail->Password
.
线索在异常的名称中:SendAsDenied
;它是说您不能使用除您的用户名以外的任何其他地址作为发件人地址,尤其是不能使用任意(伪造)地址。
如果您想避免伪造问题,请从您的管理员地址发送,但将用户地址设置为回复地址。这样你就不会伪造,回复就会到正确的地方。