laravel Expected response code 250 but got code "530"

laravel Expected response code 250 but got code "530"

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Fixing SMTP Authentication Errors in Laravel: Resolving Code 530

When troubleshooting mail delivery issues in Laravel, the error message "Expected response code 250 but got code '530'" is a common stumbling block. This specific SMTP error indicates an authentication failure, but the underlying cause is rarely the credentials themselves being incorrect. Instead, it almost always points to a protocol mismatch: the server requires TLS encryption before attempting to authenticate, but the client did not initiate the STARTTLS command first.

In the scenario provided, the application attempts to connect to smtp.gmail.com on port 587 using the configuration from .env. The critical misconfiguration lies in the MAIL_ENCRYPTION setting within the config/mail.php file. The environment variable specifies null, which Laravel interprets as no encryption. Consequently, the PHP mailer connects to the server in plaintext mode.

The Protocol Mismatch

Modern SMTP servers, particularly Gmail's smtp.gmail.com, do not accept unencrypted connections for authentication. They enforce security by requiring a secure handshake before processing login credentials. When you set MAIL_ENCRYPTION to null (or omit it), the library sends an EHLO command and immediately attempts AUTH LOGIN. The server rejects this sequence because, per RFC standards, it expects a STARTTLS command on port 587 before any authentication data is transmitted.

The error message explicitly states: "Must issue a STARTTLS command first." This confirms that the connection was established, but the security protocol was skipped. If you were to send credentials over an unencrypted channel, they would be intercepted in plain text, creating a significant security vulnerability. The server returns code 530 not because the username or password is wrong, but because the login attempt violated the mandatory encryption policy.

Correcting the Configuration

To resolve this, you must align your config/mail.php with the requirements of the SMTP provider. You need to explicitly set the encryption method to tls. This forces the mailer to send the STARTTLS command immediately after connecting, upgrading the connection to a secure TLS session before sending any authentication details.

Update your config/mail.php file as follows:

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'myemail@gmail.com', 'name' => 'Sample'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'), // Changed from null to 'tls'
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
];

Ensure that your .env file does not override this setting with null. If you leave the value as null in the environment file, Laravel will read that and ignore the default. It is best practice to set the environment variable explicitly:

MAIL_ENCRYPTION=tls

Verifying App Credentials

While fixing the encryption setting resolves the 530 error, it is equally important to verify the application credentials. Gmail has deprecated the use of standard passwords for less secure apps. Using the password from your Google account will likely result in a different authentication failure once TLS is enabled. You must generate an App Password from your Google Account security settings and use that string as the MAIL_PASSWORD value in your .env file.

Additionally, ensure that you are not using the Gmail address directly as the sender if it triggers spam filters, though this is secondary to the connection error. The primary focus remains on ensuring the TLS handshake completes successfully before authentication occurs. Once the encryption setting is corrected and valid App Passwords are in place, the SMTP server will accept the STARTTLS command, upgrade the connection, and return code 250 upon receiving the correct credentials.

Our network