Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) {

  $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->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->AddAttachment($path, $filename);

  var_dump( $email_config );

  $sent = $mail->Send();
    echo "Mailer Error: " . $mail->ErrorInfo ."\n";
    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:


250-SIZE 25600000
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:
Mailer Error: SMTP Error: The following recipients failed:<p>SMTP server error: 5.7.1 <localhost.localdomain>: Helo command rejected: Impossible, I am localhost

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/hosts localhost 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
share|improve this question

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/hosts:   localhost localhost.localdomain
::1         localhost localhost.localdomain   hostname.domain.tld hostname

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

share|improve this answer
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? – user143089 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 <localhost.localdomain>: Helo command rejected: Impossible, I am localhost – user143089 Sep 27 '13 at 19:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.