php 即使未启用加密,PHPMailer 也会使用 TLS 发送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39280938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:50:47  来源:igfitidea点击:

PHPMailer sends with TLS even when encryption is not enabled

phpphpmailer

提问by John Mendes

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:

我正在尝试使用没有 TLS 的 PHPMailer 发送电子邮件,但 PHPMailer 仍然尝试使用 TLS 发送电子邮件,即使我没有启用它:

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.

服务器不支持 ssl 或 tls。

Any idea?

任何的想法?

回答by Synchro

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:

这在 PHPMailer 文档中有介绍。PHPMailer 做机会性的 TLS - 如果服务器宣传它可以做 TLS(你的做的),它会自动使用它而不需要你问。您可以禁用此功能:

$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;.

从错误消息来看,这似乎是您的托管服务提供商的临时问题。如果你设置了,你会看到更多的信息$mail->SMTPDebug = 2;

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

我可以看到您的代码基于一个过时的示例,因此请确保您拥有最新版本的 PHPMailer并基于随附的示例编写代码。