Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?

Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?

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

Stefan Bogdanescu

Founder & Senior Architect

SMTP AUTH is Required for Message Submission on Port 587: Fixing Gmail PHPMailer Errors

The error message SMTP AUTH is required for message submission on port 587 is a direct response from Google's mail server, but the root cause often lies in how the client application interacts with Gmail's security policies. You cannot simply configure a standard SMTP connection to send email through Gmail anymore; the protocol itself enforces authentication for TLS connections on port 587.

When you attempt to submit an email to smtp.gmail.com using port 587 without enabling explicit authentication, Google rejects the connection immediately. This is not a configuration error within your PHP code logic, but rather a missing flag in the SMTP handshake sequence that tells the server you intend to authenticate. In modern versions of PHPMailer, this usually translates to ensuring $mail->SMTPAuth is set to true, which your provided code snippet already does. However, simply setting that flag is often insufficient because Gmail has deprecated the traditional "App Password" or simple password usage for non-secure applications and enforces two-factor authentication (2FA) strictly.

If you are using a standard email account password in the $mail->Password field, Gmail will reject the connection even if SMTPAuth is true. This happens because Gmail treats third-party applications (like PHP scripts) as untrusted unless specific conditions are met. To resolve this, you must generate an App Password from your Google Account settings. Navigate to your Google Account security page, enable 2-Factor Authentication if it isn't already active, and then create a dedicated 16-character app password for "Less secure apps" or specifically for "Mail." You must replace the valid password placeholder in your code with this specific generated string.

Furthermore, there is a critical distinction between the old PHPMailer class structure and the modern implementation. Your source material references require_once('class.phpmailer.php');. This file belongs to the legacy version of PHPMailer (prior to v5.2). While functional for decades, this class-based approach lacks many modern security features and is no longer recommended for new projects. The library has been updated to support namespaces and improved error handling. Migrating to the namespaced version (use PHPMailer\PHPMailer\PHPMailer;) is a safer bet, but if you must stick to the legacy class shown in your code, ensure that $mail->SMTPSecure = 'tls'; remains set, as port 587 requires TLS encryption for data in transit.

Another common pitfall involves the domain configuration mentioned in your source (vatandesign.ir). While this does not directly cause the port 587 authentication error, it highlights a broader issue: ensuring that your sending address matches your verified sender identity. If you are sending from MyUsername@gmail.com, Gmail is strict about headers and SPF records if you were using a custom domain relay, but for standard @gmail.com accounts, the App Password is the only hard requirement to bypass the "message submission" block.

If you are building this into a larger application ecosystem, consider how PHPMailer integrates with your stack. For instance, if you are already utilizing a framework like Laravel, the built-in Mail facade abstracts these SMTP details, allowing you to define credentials in your .env file rather than hardcoding them directly into the script. This separation of concerns improves security and makes deploying to production servers significantly safer, as sensitive keys never touch the source code repository.

Finally, verify that your connection timeout settings are adequate. Sometimes, if the server takes longer to respond to the initial EHLO command (which triggers the authentication requirement), a premature disconnect can mimic an auth error. Ensure your $mail->Timeout is set to something reasonable, like 30 seconds, and that your SMTPConnect method handles the TLS handshake gracefully before attempting to login. By switching to an App Password and ensuring the legacy class is configured for TLS, the "SMTP AUTH is required" error will vanish.

Our network