【问题标题】:PHPMailer won't send with SSL but Outlook willPHPMailer 不会使用 SSL 发送,但 Outlook 会
【发布时间】:2015-04-07 23:57:52
【问题描述】:

我在尝试使用 PHPMailer 和 SSL 在本地计算机上发送电子邮件时遇到问题(没有 SSL 也可以正常工作),我不知道从哪里开始查找错误的来源。

错误:

2015-02-08 01:13:29 连接:打开到 ssl://mail.mydomain.com:465, t=300, opt=array () 2015-02-08 01:13:29 SMTP 错误:无法连接到服务器:(0)2015-02-08 01:13:29 SMTP 连接()失败。无法发送邮件。Mailer 错误:SMTP connect() 失败。

这是我用来发送的代码:

$mail->SMTPDebug = 4;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'admin@mydomain.com';                 // SMTP username
$mail->Password = 'xxxx';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->From = 'admin@mydomain.com';
$mail->FromName = 'Mailer';
$mail->addAddress('personalemail@gmail.com');     // Add a recipient

这是我尝试过/观察到的:

  • 同样的代码在我的服务器(也存储了电子邮件服务器)上运行良好
  • 没有 SSL,我可以从本地主机或服务器发送电子邮件。
  • 我可以使用带有 SSL 的 gmail 帐户从我的家用计算机和 PHPMailer 发送邮件。
  • 使用与上述代码相同的设置,我可以在家中使用 Microsoft Outlook 通过 SSL 发送/接收消息(询问我是否要接受证书)。
  • 我已尝试刷新 DNS(使用 ipconfig /flushdns),但没有任何效果。

我真的不知道从哪里开始寻找,因为我可以使用 gmail 帐户通过 ssl 发送消息,但不能使用我自己的帐户,但是如果我使用 Outlook,我可以。

有什么我搞砸的想法吗?

编辑:

nslookup 结果:

C:\Users\xxx>nslookup mail.xxxx.com
Server:  UnKnown
Address:  192.168.1.1

Non-authoritative answer:
Name:    xxxx.com
Address:  110.232.yyy.zzz (this is correct)
Aliases:  mail.xxxx.com

$ openssl s_client -starttls smtp -crlf -connect mail.xxxx.com:465
CONNECTED(00000003)

$ openssl s_client -crlf -connect mail.xxxx.com:465
CONNECTED(00000003)
depth=1 C = US, ST = Illinois, L = Chicago, O = "Trustwave Holdings, Inc.", CN = "Trustwave Organization Validation CA, Level 2", emailAddress = ca@trustwave.com
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/CN=*.zuver.net.au/O=Zuver Pty Ltd/L=Narre Warren/ST=VIC/C=AU
   i:/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/emailAddress=ca@trustwave.com
 1 s:/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/emailAddress=ca@trustwave.com
   i:/C=US/O=SecureTrust Corporation/CN=SecureTrust CA
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIFLTCCBBWgAwIB...
-----END CERTIFICATE-----
subject=/CN=*.zuver.net.au/O=Zuver Pty Ltd/L=Narre Warren/ST=VIC/C=AU
issuer=/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/emailAddress=ca@trustwave.com
---
No client certificate CA names sent
---
SSL handshake has read 3822 bytes and written 624 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DHE-RSA-AES256-GCM-SHA384
    Session-ID: 150CD8E826D73DD132572E...
    Session-ID-ctx:
    Master-Key: CCB6C3F...
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 200 (seconds)
    TLS session ticket:
    0000 - 57 3a ...

    Start Time: 1423438080
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
220-zzz.zuver.net.au ESMTP Exim 4.84 #2 Mon, 09 Feb 2015 10:27:59 +1100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.

【问题讨论】:

  • 你在用apache吗?
  • @noob 是的,我忘了提到 php_openssl.dll 也已启用。
  • 你用端口 587 试过了吗?
  • @noob 就在那时,没有运气。
  • 您是否尝试关闭防火墙

标签: php email ssl phpmailer


【解决方案1】:

经过进一步测试,该问题仅在 PHP 5.6 中出现。它适用于 PHP 5.5。

原因是由于 PHP 5.6 中 OpenSSL 的更改,如 this 附录中所述,具体而言:

流包装器现在默认验证对等证书和主机名 使用 SSL/TLS 时

当我使用共享主机计划时,SSL 证书适用于 server1.myhosting.com,我通过 mail.mydomain.com 访问我的邮件服务器。不匹配,因为 SSL 证书是为server1.myhosting.com 颁发的

将我的代码更改为

$mail->Host = 'server1.myhosting.com';

帮我修好了。

注意我的网络托管服务提供商建议我使用server1.myhosting.com,所以这可能不适合您。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
相关资源
最近更新 更多