PHPMailer sends with TLS even when encryption is not enabled
If you are attempting to send raw SMTP traffic through a port like 587 without encryption, but your mail client or library still issues a STARTTLS command and fails with a "temporary reason" error, the issue usually lies in how the library defaults to secure connections. The specific scenario described involves PHPMailer failing to connect because it automatically attempts to upgrade the connection to TLS before authentication, even when the developer has not explicitly requested encryption or when the server does not support it at that moment.
In the provided code snippet, the user sets $mail->IsSMTP() and defines the port as 587. While the comment //$mail->SMTPSecure = 'ssl'; suggests they intended to disable TLS by leaving it commented out, PHPMailer's default behavior for port 587 often implies an expectation of STARTTLS. When you do not explicitly set $mail->SMTPSecure to an empty string or 'none', the library may attempt a secure handshake. The debug log confirms this:
CLIENT -> SERVER: EHLO www.johnmendes.com.br
CLIENT -> SERVER: STARTTLS
SMTP ERROR: STARTTLS command failed: 454 TLS not available due to temporary reason
The server responded with code 454, which indicates a temporary failure rather than a hard "no" or a permanent refusal. This often happens when the mail server is busy, has certificate issues, or simply does not support STARTTLS on that specific port at that moment. However, if your goal is to send unencrypted traffic (STARTTLS disabled), you must explicitly tell PHPMailer not to attempt the upgrade.
To disable TLS in PHPMailer, you need to set the SMTPSecure property directly to an empty string or 'none'. Additionally, ensure the $mail->SMTPAutoTLS property is handled correctly. In older versions of PHPMailer, the default behavior might vary depending on the specific version installed. If you are using a version where SMTPAutoTLS defaults to true, it will attempt STARTTLS unless explicitly disabled.
Here is how to configure the class to strictly avoid TLS attempts:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'site.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'contact@site.com.br';
$mail->Password = 'pass';
$mail->SMTPDebug = 1;
// Explicitly disable TLS/SSL
$mail->SMTPSecure = ''; // Or set to 'none' depending on your version requirements
$mail->SMTPAutoTLS = false; // Prevents automatic TLS negotiation if not configured
$mail->SetFrom($Username);
$mail->Subject = $Topic;
$mail->MsgHTML($Message);
$mail->AddAddress($To);
if(!$mail->Send()) {
echo 'Error: ' . $mail->ErrorInfo;
} else {
echo 'E-mail sent!';
}
By setting $mail->SMTPSecure = '', you instruct PHPMailer to treat the connection as plain text. If the server requires STARTTLS for authentication on port 587, this configuration will still fail, which is a crucial distinction: disabling TLS does not mean the server allows unencrypted traffic; it means your client won't try to encrypt it.
The Trap of Port 587
Port 587 is conventionally reserved for SMTP submission with STARTTLS. If a mail server listens on port 587 but does not support TLS, it is often misconfigured or legacy infrastructure. When you send a STARTTLS command to such a server, the response 454 TLS not available due to temporary reason is technically correct from the server's perspectiveâit acknowledges your request but cannot fulfill it temporarily.
If your intention is to use an unencrypted connection on port 25 (which is less common for submission) or if the server explicitly rejects STARTTLS, you must ensure your client aligns with the server's capabilities. However, sending unencrypted credentials over a network interface like port 587 without TLS is inherently insecure and should be avoided in production environments unless internal firewalls strictly segment the traffic.
For modern Laravel applications, the underlying PHPMailer instance often needs to be configured similarly if you are extending the mail system or using legacy components. Always verify the exact version of PHPMailer installed, as properties like SMTPSecure have changed behavior between versions 5.0 and 6.x. If you are transitioning to a newer stack, consider whether the specific mail server supports AUTH PLAIN or AUTH LOGIN over a plaintext connection, though most modern providers mandate TLS for all authenticated sessions regardless of the port.