0

我在通过启用了 ssl 的 SMTP 使用 PHPMailer 发送电子邮件时遇到问题。

$mail = new PHPMailer;
// HTML email!
$mail->IsHTML(true);
$mail->isSMTP();
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "server.co.tz";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "xxxxxxx";
//Password to use for SMTP authentication
$mail->Password = "yyyyyyy";

当我运行脚本时,出现以下错误:

Mailer Error: SMTP connect() failed.

在 exim4 日志中:

2016-02-24 11:02:20 TLS error on connection from [197.215.254.114] (gnutls_handshake): A TLS fatal alert has been received.

我不知道这里出了什么问题。

我为我的电子邮件客户端定期使用 SMTP,并且 SSL 证书是有效的。

更新:

获得最新版本并将调试设置为 3,但仍然没有运气:

Connection: opening to ssl://fsm.co.tz:465, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
4

2 回答 2

0

截至今天@PHPMailer 6.1.4 版这些对我有用:-

    $email->SMTPDebug = SMTP::DEBUG_SERVER; 
    $email->isSMTP(); 
    $email->Host       = 'host';
    $email->SMTPAuth   = true; 
    $email->Username   = 'username';  
    $email->Password   = 'password'; 
    $email->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $email->Port       = 465;   
于 2020-02-22T11:18:16.197 回答
-2

解决方案是将以下内容添加到配置中:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => false
    )
);
于 2016-02-24T08:46:19.443 回答