Search code examples
phpimapphpmailer

PHP Mailer : MAIL not accepted from server.The following From address failed


I'm having issues sending mil using PHP Mailer. I have tried two different mail servers. To one of these mail servers I have access through a local IP as well. When I use the local IP as value for the $server variable, things work fine and mails go through. But when I use the external IP for the mail server things don't work and I get the error shown below. Same is the case while using another mail server's DNS. Exact same error both times.

$mail = new PHPMailer;
$server = 'mail.xxxx.com';
$smtpPort = '25';
$username = 'xxxx@xxxx.com';
$password = 'xxxxx';

$mail->isSMTP();                                        // Set mailer to use SMTP
$mail->Host = $server;                      // Specify main and backup server
$mail->SMTPAuth = true;                                 // Enable SMTP authentication
$mail->Username = $username;                            // SMTP username
$mail->Password = $password;                                // SMTP password    
$mail->From = 'xxxx@xxxxxx.com';
$mail->addAddress('abijeet@xxxxx.asia', 'xxxxx');           // Add a recipient

$mail->WordWrap = 50;                          // Set word wrap to 50 characters
$mail->isHTML(true);                           // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

This is the debug output from the PHPMailer for both servers when external IP or a DNS is used-

SMTP -> FROM SERVER:220 mail.xxxxxx.com ESMTP Postfix
SMTP -> FROM SERVER: 250-mail.xxxxxx.com 250-PIPELINING 250-SIZE 15728640 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN
SMTP -> FROM SERVER:
SMTP -> ERROR: MAIL not accepted from server:
Message could not be sent.Mailer Error: The following From address failed: xxx@xxxxxx.comSMTP server error: 

SMTP -> FROM SERVER:220 xxxxx.com ESMTP Citadel server ready.
SMTP -> FROM SERVER: 250-Hello localhost (xxx.xxxxx.net [xxx.xxx.xxx.xxx]) 250-HELP 250-SIZE 10485760 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250 8BITMIME
SMTP -> FROM SERVER:
SMTP -> ERROR: MAIL not accepted from server:
Message could not be sent.Mailer Error: The following From address failed: abijeet@xxxx.comSMTP server error: 

Also note that I was able to successfully connect to the DNS based mail server using Windows Live Mail, so it's not a port issue.


Solution

  • I updated the version of PHP mailer and things seem to be working now. No changes had to be made to the code. The older version that was being used was 5.1. Current version is 5.2.7