Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer sends with TLS even when encryption is not enabled

I am trying sending email using PHPMailer without TLS, but PHPMailer still tries to send email with TLS even if I do not enable it:

include_once("PHPMailer-master\PHPMailerAutoload.php");

$To = '[email protected]';
$Subject = 'Topic';
$Message = 'msg test';

$Host = 'site.com.br';
$Username = '[email protected]';
$Password = 'pass';
$Port = "587";

$mail = new PHPMailer();
$body = $Message;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = $Host; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->SMTPSecure = 'ssl'; //or tsl -> switched off
$mail->Port = $Port; // set the SMTP port for the service server
$mail->Username = $Username; // account username
$mail->Password = $Password; // account password

$mail->SetFrom($Username);
$mail->Subject = $Subject;
$mail->MsgHTML($Message);
$mail->AddAddress($To);

if(!$mail->Send()) {
    $mensagemRetorno = 'Error: '. print($mail->ErrorInfo);
    echo $mensagemRetorno;
} else {
    $mensagemRetorno = 'E-mail sent!';
    echo $mensagemRetorno;
}

After send email, I got this message:

2016-09-01 21:08:55 CLIENT -> SERVER: EHLO www.johnmendes.com.br
2016-09-01 21:08:55 CLIENT -> SERVER: STARTTLS
2016-09-01 21:08:55 SMTP ERROR: STARTTLS command failed: 454 TLS not available due to temporary reason
2016-09-01 21:08:55 SMTP Error: Could not connect to SMTP host.
2016-09-01 21:08:55 CLIENT -> SERVER: QUIT
2016-09-01 21:08:55 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Erro ao enviar e-mail: 1

The server doesn't support ssl or tls.

Any idea?

like image 562
John Mendes Avatar asked Sep 01 '16 21:09

John Mendes


People also ask

Does Smtps use TLS?

SMTPS uses additional SSL or TLS cryptographic protocols for improved security, and the extra "S" stands for SECURE! By default, the SMTP protocol lacks encryption and can be used to send emails without any protection in place.

Is PHPMailer secure?

PHPMailer doesn't create/use any SQL itself, nor does it have anything to do with javascript, so it's secure on those fronts. It is often used alongside code that does both, but that's not PHPMailer's concern.

How do I enable TLS in SMTP?

Enable Outbound TLSSelect a SMTP Virtual Server -> Right Click -> Properties -> Delivery -> Outbound Security -> Check TLS encryption -> Click OK -> Click Apply .

Does PHPMailer use SMTP?

PHPMailer provides powerful functionality to create HTML emails with attachments and send them to multiple recipients via SMTP or a local webserver.


2 Answers

This is covered in the PHPMailer docs. PHPMailer does opportunistic TLS - if the server advertises that it can do TLS (which yours does), it will use it automatically without you asking. You can disable this:

$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;

From the error message, it looks like this is a temporary problem on your hosting provider. You would see more info if you set $mail->SMTPDebug = 2;.

I can see you've based your code on an obsolete example, so make sure you have the latest version of PHPMailer and base your code on the examples supplied with it.

like image 117
Synchro Avatar answered Sep 23 '22 17:09

Synchro


I had the same problem using one.com: SMTP 465 wasn't working.

I could using port 25 with this configuration in phpmailer:

$mail->Host = 'send.one.com';
$mail->SMTPAuth = true;
$mail->Username = "***";
$mail->Password = "******";
$mail->From = "***";
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = 'none';
$mail->Port = 25;
like image 24
gtamborero Avatar answered Sep 20 '22 17:09

gtamborero