When sending emails using PHP's PEAR Mail package, many developers encounter an issue where their emails show "helo=localhost" in the headers. This default configuration can cause deliverability issues as many mail servers perform reverse DNS lookups and verify that the HELO matches your domain's DNS records.
Proper HELO/EHLO configuration is crucial because:
- Spam filters often reject messages with mismatched HELO identifiers
- Many receiving servers perform forward-confirmed reverse DNS checks
- Professional email systems expect domain alignment between HELO and From addresses
For a domain "domain.com" with MX records at "mail.domain.com", your HELO should match one of these:
- domain.com (most common and recommended)
- mail.domain.com (if you want to be more specific)
Here's how to properly configure the HELO parameter in PEAR Mail:
require_once "Mail.php";
$params = array(
'host' => 'mail.domain.com',
'port' => 25,
'auth' => true,
'username' => 'user@domain.com',
'password' => 'password',
'localhost' => 'domain.com' // This sets the HELO/EHLO value
);
$mailer = Mail::factory('smtp', $params);
After implementation, check your email headers. They should now show:
Received: from domain.com ([12.34.56.78]) helo=domain.com
instead of the previous:
Received: from domain.com ([12.34.56.78]) helo=localhost
If you're still having problems:
- Ensure your server's reverse DNS (PTR record) matches your HELO
- Verify your SPF record includes the HELO domain
- Check for any firewall restrictions on outbound SMTP
- Test with different ports (25, 587, 465) if one is blocked
For more complex setups, you might need:
$params = array(
'host' => 'mail.domain.com',
'port' => 587,
'localhost' => 'mailer1.domain.com',
'persist' => true,
'pipelining' => true,
'timeout' => 30
);
When sending emails through SMTP, the HELO/EHLO command is your first handshake with the recipient's mail server. Many spam filters will check whether the domain you declare in HELO matches:
- Your MX records (mail.domain.com in your case)
- Your reverse DNS (PTR record)
- The domain in your From: address
Your current configuration shows:
Received: from domain.com ([12.34.56.78] helo=localhost)
This is problematic because:
- localhost isn't a valid domain
- It doesn't match your actual domain (domain.com)
- Many spam filters will penalize or reject such emails
Here's how to correctly set the HELO parameter:
require_once "Mail.php"; $params = array( 'host' => 'mail.domain.com', 'auth' => true, 'username' => 'user@domain.com', 'password' => 'password', 'localhost' => 'domain.com' // This sets the HELO/EHLO value ); $mail = Mail::factory('smtp', $params);
After implementation, check your email headers. They should now show:
Received: from domain.com ([12.34.56.78] helo=domain.com)
You can verify this using:
telnet mail.domain.com 25 EHLO domain.com
- Ensure your PTR record matches your HELO domain
- Set up SPF records for domain.com
- Consider implementing DKIM signing
- Test your configuration using tools like Mail-Tester.com
If you encounter problems:
// For debugging, add these parameters: $params['debug'] = true; $params['persist'] = false;
Common error messages and solutions:
- "501 Invalid domain address" - Check your domain syntax
- "550 Reverse DNS mismatch" - Verify your PTR records
- "504 HELO requires domain address" - Ensure you're not using localhost