Expected response code 250 but got code "550" Laravel swift mailer

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Decoding the SMTP Nightmare: Why You Get Error 550 When Sending Emails in Laravel

As a senior developer, I’ve seen countless frustrating debugging sessions involving email delivery. The transition from a successful test in Tinker to a failure in production code is a common pain point. Today, we are diving deep into a specific, tricky error encountered when using Laravel's Mailer: the Swift_TransportException (550) error.

This post will dissect why you are seeing the message "550 Bad HELO - Host impersonating domain name [mydomain.com]" and guide you through diagnosing this issue, especially when dealing with custom DNS setups and external mail relays.


Understanding the 550 SMTP Error

The error code 550 is an SMTP response indicating a permanent failure or error during the communication handshake. The specific message, "Bad HELO - Host impersonating domain name [mydomain.com]", points directly to a problem with hostname verification during the initial connection setup (the HELO command).

In simple terms: the external mail server you are trying to connect to does not recognize or trust the hostname that your application is presenting to it as the sender's domain. This usually happens when there is a mismatch between the FQDN used in your SMTP configuration and the actual network identity of the server initiating the connection.

Diagnosing the Root Cause: Application vs. Infrastructure

When debugging mail failures, we must separate the problem into two layers: the application layer (Laravel) and the infrastructure layer (DNS, Server Configuration, MTA setup). Given your context—running on an Ubuntu server with custom DNS and external forwarding—the issue is almost certainly rooted in the infrastructure.

Phase 1: Checking Laravel Configuration (The Basics)

First, let's ensure the application configuration isn't introducing the error. Your setup details look standard for SMTP configuration:

// .env file example
MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com // This is the hostname being presented
MAIL_PORT=587
MAIL_USERNAME=info@mydomain.com
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls // Or ssl

While these settings look correct, they only define where Laravel tries to send the request. The problem arises when that request hits your Ubuntu server and is forwarded externally.

Phase 2: Investigating Server and DNS Issues (The Likely Culprit)

Since you are running on a custom Ubuntu setup with bind9 configured, the issue likely lies in how your server is handling outbound connections and domain impersonation checks enforced by the external mail server.

Here are the critical areas to investigate:

1. Reverse DNS (PTR Record):
For an external mail server to trust an email coming from a specific IP address, it checks the PTR record associated with that IP. If your Ubuntu server's IP address does not correctly resolve back to mail.mydomain.com (or whatever hostname is expected), the connection will be immediately rejected as impersonation.

  • Action: Check the PTR record for the public IP address of your Ubuntu server using tools like dig -x [your_server_ip] or an online lookup tool. Ensure it matches the domain you are trying to relay from.

2. Hostname Resolution and FQDN:
Verify that the hostname specified in MAIL_HOST (mail.mydomain.com) is correctly resolved by your Ubuntu server, and ensure there are no conflicting DNS entries for that IP address.

3. SMTP Relay Configuration (If applicable):
If you are using an external mail server as a true relay, check the settings on that external server. It might have stricter hostname validation rules than you expect. Ensure the credentials (MAIL_USERNAME/MAIL_PASSWORD) are valid for that specific relay connection.

Best Practices for Robust Email Delivery

To build truly resilient applications like those on Laravel Company, we must treat email delivery as a complex network process, not just a simple function call.

  1. Use Environment Variables Securely: Always manage sensitive credentials in .env files and ensure proper file permissions.
  2. Test End-to-End: Before assuming the error is infrastructure-related, test the full path. Try using a simpler tool (like Postman or a dedicated SMTP client) to send mail directly from the server's command line to isolate whether Laravel or the underlying server configuration is at fault.
  3. Monitor Logs: Configure detailed logging on your Ubuntu server. The actual SMTP error message might be logged by the Mail Transfer Agent (MTA), providing clearer context than what Laravel receives.

Conclusion

The 550 Bad HELO - Host impersonating domain name error is a classic sign of a network identity mismatch, usually involving DNS or IP routing issues between your application server and the external mail relay. Don't focus solely on the Laravel code; pivot your debugging efforts to the network configuration of your Ubuntu server. By meticulously checking PTR records and hostname resolution, you will resolve this impersonation error and ensure your Laravel applications can reliably deliver emails.