1
votes

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 = '[email protected]';                            // 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('[email protected]');  // 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';
}
?>
2
the smtp message says that your mailhost don't allow relaying mails. so you need to ask your provider to allow relaying for your serversHentschel
okay, so let me check with them.Django Anonymous
I'm not finding any problem with your code. have you tried with other smtp(gmail). $body = wordwrap($body, 70, "\r\n"); that will wrap your email body. kindly check with your mailhost provider and try with short html bodysas

2 Answers

4
votes

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.

0
votes

-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.