PHPMailer失败并使用ssl

时间:2016-02-24 08:06:38

标签: email ssl phpmailer exim4

我很难通过我的SMTP发送带有PHPMailer的电子邮件,这是启用了ssl。

$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 regurarly,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

2 个答案:

答案 0 :(得分: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;   

答案 1 :(得分:-1)

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

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