error Message: Expected response code 220 but got an empty response" with exception "Swift_TransportException",
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Decoding the Error: Resolving "Expected response code 220 but got an empty response" in Laravel Email Notifications
As a senior developer, I often encounter frustrating errors when setting up external services within a framework. The specific error you are facing—error Message: Expected response code 220 but got an empty response with the exception Swift_TransportException—is a classic sign that your application is successfully initiating a connection to an SMTP server, but the server is failing to respond correctly during the initial handshake or authentication process.
This issue almost always resides outside of the main Laravel code itself; it lives in the configuration of your mail driver, your environment variables, or network connectivity. Let's dive into why this happens and how we can systematically debug and resolve it when setting up account confirmation emails with Passport authentication flows.
Understanding the SMTP Error Context
The error message Expected response code 220 but got an empty response relates directly to the Simple Mail Transfer Protocol (SMTP) communication. Code 220 is the standard positive response indicating that the server is ready to accept commands. When you receive an empty response instead, it means the connection was established, but the mail server either rejected the connection immediately or failed to send the expected protocol response.
In essence, your Laravel application successfully tried to talk to the email server (like Gmail's SMTP), but the server did not respond as expected, leading to a transport exception. This strongly points toward configuration problems related to credentials, ports, security settings, or network restrictions rather than a bug in your notification logic.
Systematic Troubleshooting Steps for Laravel Mail Configuration
Since you have already attempted clearing the cache and adjusting .env and mail.php, we need to look deeper into the specific constraints of using external SMTP services.
1. Scrutinize Environment Variables (.env)
The most common failure points are incorrect credentials or restrictive security settings, especially when using services like Gmail.
- App Passwords for Gmail: If you are using a standard Google account (Gmail), modern security protocols require you to use an "App Password" instead of your regular account password. Standard login attempts often fail due to stricter security measures. Ensure the
MAIL_PASSWORDvariable uses a dedicated, generated App Password. - Encryption Setting: You have set
MAIL_ENCRYPTION=null. While this sometimes works for older setups, modern SMTP servers strongly recommend using TLS or SSL. Try explicitly setting it totls(as shown in yourmail.phpexample) and ensure the host/port combination is correct for your specific provider (e.g.,smtp.gmail.com:587).
2. Review Mail Configuration (mail.php)
Your configuration file acts as the bridge between Laravel and the SMTP server. Take a careful look at how you are defining the connection parameters:
// Example from your provided mail.php setup
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'), // Ensure this is set correctly
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
Ensure that the values loaded from your .env file are correctly mapped here, and that the protocol (TLS/SSL) matches what your SMTP host expects. A mismatch here will cause the server to reject the connection immediately.
3. Network and Server Constraints
Sometimes the issue is environmental rather than configuration:
- Firewalls: If you are running this on a local machine or a restricted server, ensure that outbound connections on ports 587 (or 465 for SSL) are not blocked by any firewall rules.
- Server-Side Restrictions: Some hosting providers impose strict limits or have specific security policies that block outgoing mail requests if they don't conform to their internal standards.
Best Practices for Robust Email Sending
When building robust systems like those on Laravel, adopting best practices ensures reliability. Instead of hardcoding sensitive details, always rely on environment variables and keep your configuration clean. Furthermore, think about scalability; if you anticipate high volumes of emails, consider using dedicated transactional email services (like SendGrid or Mailgun) rather than relying solely on personal SMTP accounts, which can be rate-limited or flagged by providers like Google.
In summary, the Swift_TransportException for an empty response during notification delivery is almost always a connectivity or authentication failure with the mail server. By systematically checking your .env variables (especially credentials and encryption settings) against the requirements of your chosen SMTP host, you will isolate and resolve this frustrating error. Happy coding!