Error in sending email using phpmailer - Relaying disallowed SMTP Error: data not accepted

安稳与你 提交于 2019-12-13 17:28:23

问题


I am trying to send email using phpmailer, but the following code fails to send email with this error:

SMTP ERROR: DATA END command failed: 553 Relaying disallowed SMTP Error: data not accepted. Mailer Error: SMTP Error: data not accepted.

Code is below:

<?php
require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();
$mail->CharSet = 'UTF-8';
                                      // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com';  // Specify main and backup server
$mail->SMTPDebug  = 1;
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'noreply@website.com';                            // SMTP username
$mail->Password = '846Support.x.1';                           // SMTP password
$mail->SMTPSecure = 'ssl';   
$mail->Port = 465;                         // Enable encryption, 'ssl' also accepted

$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->addAddress('info@website.com');  // Add a recipient
$mail->addReplyTo($_POST['email'], $_POST['name']);

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->isHTML(true);                                  // Set email format to HTML

$body = $_POST['message'];
$body = wordwrap($body, 70, "\r\n");
$body = $body . "\r\n" . "Phone: " .$_POST['phone'];

$mail->Subject = 'Contact Form';
$mail->Body    = $body;

if(!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit();
}
else
{
    echo 'success';
}
?>

回答1:


I guess Zoho SMTP server doesn't accept sending mail with from e-mail diferent of smtp login mail.. I changed and it has passed imediatelly.




回答2:


-You can still use Zoho with little change. - The problem: relay is disallowed because the From address (which user entered) and Sender (which you specified to be admin email) address are not matched. You can visit wp-admin/Tools/Email Log to verify. -Work around: change From address with Sender address, you still know who is sending this email, look at Return Part. - Hands on: go to /wp-content/plugins/postman-smtp/Postman/Postman-Mail/PostmanZendMailEngine.php, go to near end of this file and comment this line: $senderEmail = $sender->getEmail (); then the address with Send value, see below for final result // $senderEmail = $sender->getEmail (); $senderEmail = $this->transport->getFromEmailAddress (); - It should work now.



来源:https://stackoverflow.com/questions/20635008/error-in-sending-email-using-phpmailer-relaying-disallowed-smtp-error-data-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!