【问题标题】:PHPMailer failing with sslPHPMailer 使用 ssl 失败
【发布时间】:2016-02-24 08:06:37
【问题描述】:

我在通过启用 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

【问题讨论】:

  • 打开调试输出怎么样? SMTPDebug = 3 应该足够了。
  • 看起来你也在运行旧版本的 PHPMailer,所以get the latest

标签: email ssl phpmailer exim4


【解决方案1】:

截至今天@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;   

【讨论】:

    【解决方案2】:

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

    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => false
        )
    );
    

    【讨论】:

    • 这不是真正的解决方案,而是(临时)解决方法。尽管如此,这是“正确的”,因为它可以让您在使用自签名或其他错误证书进行测试时快速启动并运行。如果可行,“正确”的解决方案是为您的邮件服务器获取正确的证书。
    猜你喜欢
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2014-07-31
    • 2014-06-13
    • 2015-08-09
    • 1970-01-01
    相关资源
    最近更新 更多