phpmailer通过ssl发送电子邮件:证书已过期

时间:2018-11-02 06:49:25

标签: openssl smtp ssl-certificate phpmailer pear

我写了一个新的php脚本,但是当我尝试与服务器连接时却遇到了一些问题:

  1. 我可以在Windows程序中使用相同的smtp ip:port,并且可以正常工作。

  2. 我可以使用它并与雷鸟一起工作,但是他给我的证书在发送任何东西之前已过期

enter image description here

代码在下面。

<?php
/**
 * Created by PhpStorm.
 * User: n0b0dy
 * Date: 11/1/18
 * Time: 9:40 PM
 */
require("/usr/share/php/libphp-phpmailer/class.phpmailer.php");
require '/usr/share/php/libphp-phpmailer/PHPMailerAutoload.php';
require '/usr/share/php/libphp-phpmailer/autoload.php';
require '/usr/share/php/libphp-phpmailer/class.smtp.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
/**
$mail->SMTPOptions = array(
   'ssl' => array(
        'verify_peer' => true,
        'verify_depth' => 3,
    )
);
*/
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = 0; // authentication enabled
#$mail->SMTPAutoTLS = false;
$mail->Host = 'ssl://75.101.161.108:465';
$mail->IsHTML(true);
$mail->SetFrom("any@any.com");##### Dont care about email because of problem with connection 
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("any@gmail.com");
if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent";
}
?>

这是Phpmailer的问题

2018-11-02 06:38:23 Connection: opening to ssl://75.101.161.108:465, timeout=300, options=array (
                                      )
2018-11-02 06:38:24 SMTP ERROR: Failed to connect to server:  (0)
2018-11-02 06:38:24 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting%            

B-在此处设置smtp和代码的电子邮件

<?php
require_once "Mail.php";
include('Mail/mime.php');

$html = "TEST";// HTML version of the email
$crlf = "\r\n";
$headers = array('From' => "Test<example@any.com>",'To' => 'any@gmail.com', 'Return-Path' => 'example@any.com', 'Subject' => 'Form Pear Email');
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtpinfo["host"] = 'ssl://75.101.161.108';
$smtpinfo["port"] = '465';
$smtpinfo["auth"] = "false";
$smtpinfo["socket_options"] = array('ssl' => array('verify_peer_name' => false,'verify_peer' => false,'allow_self_signed' => true));
$smtpinfo["timeout"] = "10";
$smtpinfo["debug"] = "true";
$smtp = Mail::factory('smtp',$smtpinfo);
$mail = $smtp->send('any@gmail.com', $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo("WORKING\n");
}
?>

及相关问题,

DEBUG: Send: QUIT

Failed to connect to ssl://75.101.161.108:465 [SMTP: Failed to connect socket: stream_socket_client(): unable to connect to ssl://75.101.161.108:465 (Unknown error) (code: -1, response: )]

我通过此命令使用openssl

openssl s_client -connect 75.101.161.108:465

结果

  CONNECTED(00000003)
140527088361920:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1399:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 176 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1541150392
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no
---

所以,请问有人可以帮助我吗?

关于erveryone

1 个答案:

答案 0 :(得分:1)

第一步:您正在使用旧版本的PHPMailer; get the latest

您的代码基于提供的示例-特别是您应该使用composer来加载它,但是使用旧代码,您不需要加载类自动加载器。

通知不正确。不仅是它已过期,而且是名称不匹配,已过期且未由已知的CA签名。这表明您的连接已被拦截并重定向到您期望之外的其他地方。正是TLS可以保护您免受其破坏,并且按预期工作。

您不应禁用证书验证。弄清楚连接发生了什么(请参阅PHPMailer故障排除指南中的步骤),并跟踪ISP对出站SMTP连接进行的操作,然后使用openssl命令检查所获得的证书。由于您隐藏了真实的主机名,因此我们无法为您做任何事情。