Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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
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? –  awashburn 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 –  awashburn Sep 27 '13 at 19:28

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.