1

I am trying to send mail in a PHP script via the PHPMailer library. The following code has successfully sent emails in the past without warnings:

function mail_attachment($filename, $path, $mailto, $subject, $message) {
  include("PHPMailer_5.2.3/class.phpmailer.php");
  include("PHPMailer_5.2.3/class.smtp.php");

  $email_config = parse_ini_file('email.cfg');
  $from  = $email_config['sender'];
  $alias = $email_config['alias' ];
  $smtp  = $email_config['host'  ];
  $port  = $email_config['port'  ];

  $mail             = new PHPMailer();
  $mail->SMTPDebug  = 2;
  $mail->IsHTML(false);       // send as HTML?
  $mail->WordWrap   = 50;     // set word wrap

  $mail->IsSMTP();
  $mail->Host       = $smtp;  // set the host SMTP server
  $mail->Port       = $port;  // set the host SMTP port

  $mail->Subject    = $subject;
  $mail->Body       = $message;
  $mail->SetFrom(   $from, $alias);
  $mail->AddReplyTo($from, $alias);
  $mail->AddAddress($mailto);
  $mail->AddAttachment($path, $filename);

  var_dump( $email_config );

  $sent = $mail->Send();
  if(!$sent)
    echo "Mailer Error: " . $mail->ErrorInfo ."\n";
  else
    echo "Message has been sent\n";
  return $sent;
}

Suddenly the automated reporting emails stopped showing up in people's inboxes and the following messages were generated:

SMTP -> FROM SERVER:220 relay-8.dlfw.twtelecom.net ESMTP Postfix

<br />SMTP -> FROM SERVER: 250-relay-8.dlfw.twtelecom.net
250-PIPELINING
250-SIZE 25600000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

<br />SMTP -> FROM SERVER:250 2.1.0 Ok

<br />SMTP -> FROM SERVER:554 5.7.1 <localhost.localdomain>: Helo command rejected: Impossible, I am localhost

<br />SMTP -> ERROR: RCPT not accepted from server: 554 5.7.1 <localhost.localdomain>: Helo command rejected: Impossible, I am localhost

<br />SMTP Error: The following recipients failed: dataintegrity@corporate-domain.com
Mailer Error: SMTP Error: The following recipients failed: dataintegrity@corporate-domain.com<p>SMTP server error: 5.7.1 <localhost.localdomain>: Helo command rejected: Impossible, I am localhost
</p>

Mail Was NOT Successfully Sent!

Do you have any ideas on why the code stopped working?

Is the problem on my end or the remote mail server?

I have the following hostname configurations:

/etc/hostname

Dev07

/etc/hosts

127.0.0.1 localhost
127.0.1.1 lamp

#Required for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

1 Answers1

2

It would appear that the remote server does not like the fact that your server is reporting that it is localhost.localdomain in the HELO you're sending.

This could result from the remote server configuring their SMTP service to reject invalid HELOs. It's also possible that something changed on your local server, such that the hostname is no longer configured correctly.

I would recommend setting your hostname to something so that sendmail does not report as localhost.localdomain. While, you are at it, it's also a generally good idea to update /etc/hosts with the ip address, FQDN, and host name of the server.

There's a tutorial here on how to do it.

/etc/hostname:
hostname.domain.tld


/etc/hosts:
127.0.0.1   localhost localhost.localdomain
::1         localhost localhost.localdomain

1.2.3.4   hostname.domain.tld hostname

If you have a RedHat/CentOS based system, edit /etc/sysconfig/network and set:

HOSTNAME=hostname.domain.tld
Justin Pearce
  • 1,005
  • 10
  • 13
  • Setting the server hostname is indeed the way to fix this. – Michael Hampton Sep 27 '13 at 19:05
  • Thank you for the recommendation, I have updated my question with my host name configurations. Would you please suggest what specific changes to make? –  Sep 27 '13 at 19:16
  • @awashburn Did you restart all of the involved services? – Michael Hampton Sep 27 '13 at 19:18
  • @awashburn It also appears that you didn't update your `/etc/hosts` file – Justin Pearce Sep 27 '13 at 19:23
  • I restarted the machine but the `/etc/hosts` & `/etc/hostname` edits did not affect the email SMTP response. Still says `FROM SERVER:554 5.7.1 : Helo command rejected: Impossible, I am localhost` –  Sep 27 '13 at 19:28
  • @awashburn You might try following this tutorial in case there was a step that was glossed over: http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/ – Justin Pearce Sep 27 '13 at 20:40