PHPMailer发送邮件时卡住了。

8
我曾经在一台内部共用的桌面电脑上成功地使用WAMPSERVER设置了一个Web应用程序,该应用程序使用PHPMailer连接到一个没有加密或身份验证的内部SMTP服务器并且运行良好。但是这台桌面电脑出现故障后,我将其迁移到了一台“新”的桌面电脑上。我有一个SVN设置,因此我甚至使用了大部分相同的文件和配置。其中可能会有所不同的是旧的桌面电脑是64位的,而新的是32位的。这意味着我正在使用不同版本的WAMPSERVER。
邮件发送器卡住了。我既没有收到PHP错误也没有超时,我只是永远无法到达我的脚本的结尾。这个疯狂的部分是它可以使用身份验证、ssl和gmail。它只是不能满足我需要的简单情况。
以下内容可以正常工作:
<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "myemail@gmail.com";  // GMAIL username
$mail->Password   = "mypassword";            // GMAIL password
$mail->AddAddress('toemail@supersecret.com', 'John Doe');
$mail->SetFrom('something@gmail.com', 'First Last');
$mail->Send();
?>

这曾经可以做到,但现在不行了:

<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.internal.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
$mail->Port       = 25;                   // set the SMTP port for the GMAIL server
$mail->AddAddress('myaddress@somewhere.com', 'John Doe');
$mail->SetFrom('someaddress@mightbereal.com', 'First Last');
$mail->Send();
?>

我从debug中得到的唯一信息是:

客户端 -> SMTP:EHLO thedesktophostname

在页面上没有显示任何错误,并且在apache日志中也没有任何内容。我通常可以在那里看到PHP错误,如果它们没有被显示。
我可以从桌面电脑telnet到主机的25号端口,甚至输入EHLO命令并从服务器得到良好的响应。
我不记得以前有这个问题,尽管我可能已经解决过一次。我在这里或者在谷歌上找不到任何有用的信息。
请帮忙解决。谢谢。

下一个问题是:您能否使用fsockopen()连接到SMTP服务器,如果手动编写EHLO行,会得到什么结果? - Wrikken
如果我注释掉那一行,它就会到达下一个fgets并超时,但在fsockopen和fwrite上似乎没问题。 - user2221400
在你的 EHLO 字符串后面添加 "\r\n",然后会发生什么? - Wrikken
唉,最后一步了,我已经没有其它想法了:如果“fread($socket,1);”起作用,请启用“auto_detect_line_endings”.... - Wrikken
很奇怪...我会检查TCP流量,看看是否有连接并返回。 - Wrikken
显示剩余9条评论
5个回答

14

劫持这篇文章来说我也遇到了同样的问题,但是我将端口设置为465而没有在示例中设置SMTPSecure为'ssl',默认情况下它被设置为TLS


1
将smtpsecure设置为ssl也解决了我的问题,我正在使用hostgator。 - Ersel Aker
谢谢!从本地主机通过Zoho发送需要进行此配置。 - AaronDanielson

4
如果你在 Hostgator(共享主机)上托管了服务器,这是我解决问题的方法:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
(尽管 PHPMailer 的官方示例建议使用 ENCRYPTION_STARTTLS)。

除非他已经设置了 ssl,这是 ENCRYPTION_SMTPS 的值。 - jave.web

2

不幸的是,这可能对其他遇到同样问题的人没有帮助,但我只需将端口更改为465,就能使一切正常运作。


哈,这也是我的问题。我将它设置为993,但那是用于TLS的。 - Wilbo Baggins

1

最终找到了我的配置解决方案。
只需将ssl://添加到smtp.google.com的前面:
$mail->Host = 'ssl://smtp.gmail.com';


谢谢,这个方法解决了 SendGrid 卡住的问题,你太棒了,谢谢! - Andy

1
我遇到了同样的问题。在 send 方法后没有显示任何内容。 我意识到加密方式不对,我使用了 SMTPS。
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接