【发布时间】:2014-09-29 13:41:04
【问题描述】:
在发送时事通讯类邮件时,我遇到了这个奇怪的问题。
在 for 循环中,我遍历数据库中的所有用户,并尝试向他们发送包含一些基本信息的 HTML 邮件。现在问题是前 200 封左右的邮件运行良好,但随后脚本崩溃并给出以下错误:
Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:140D00CF:SSL routines:SSL_write:protocol is shutdown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 263 Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:140D00CF:SSL routines:SSL_write:protocol is shutdown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 263 Fatal error: Uncaught exception 'Zend\Mail\Protocol\Exception\RuntimeException' with message 'Could not read from smtp.gmail.com' in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php:308 Stack trace: #0 /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php(339): Zend\Mail\Protocol\AbstractProtocol->_receive(300) #1 /opt/zendframework2/library/Zend/Mail/Protocol/Smtp.php(358): Zend\Mail\Protocol\AbstractProtocol->_expect(221, 300) #2 /opt/zendframework2/library/Zend/Mail/Protocol/Smtp.php(394): Zend\Mail\Protocol\Smtp->quit() #3 /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php(115): Zend\Mail\Protocol\Smtp->_disconnect() #4 [internal function]: Zend\Mail\Protocol\AbstractProtocol->__destruct() #5 {main} thrown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 308
现在,我对 smtp、ssl 和 tls 不熟悉,但我认为错误中最重要的一行是:“无法从 smtp.gmail.com 读取”。这对我来说没有任何意义。
我们一直在发送电子邮件(丢失密码、注册邮件等),这总是(据我所知)工作正常。该脚本在短时间内发送了太多邮件后就会崩溃。
好的,这就是问题所在,现在让我解释一下设置:)
我在标准 LAMP 服务器 ( PHP 5.3.10 ) 上运行 Zend 2.2.6 并使用 Zend 提供的标准 SMTP 邮件脚本。我们将 Google 商业应用程序用作邮件客户端。以下是邮件脚本的前几行:
<?PHP
namespace Mail\Mails;
use Zend\Mail;
use Zend\Mail\Message;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
use Mail\Config\Config;
class Base
{
private $transport, $text, $html, $to, $subject;
public function __construct()
{
$config = new Config();
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'mydomain.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'username' => $config->username,
'password' => $config->password,
'ssl' => 'tls'
),
));
$transport->setOptions($options);
$this->transport = $transport;
// This happens in different parts of the code.
$this->subject( $subject );
$this->to( $address );
$this->html( $html );
$this->text( $text );
$this->send();
}
?>
到目前为止我所尝试的:
- 再次运行脚本
- 这有不同的结果:有时它中断得更早,有时它中断得更远,但这证明脚本不会在特定地址上中断。我感觉服务器有某种冷却:第一次运行它处理 200 个地址,但当我直接重新运行脚本时,它可能会在 20 个地址后中断。当我在一个小时后尝试时,脚本在大约 200 个地址后再次中断。
- 我尝试将 ssl 选项更改为“ssl”,将端口选项更改为“465”,但结果完全相同。
有人熟悉这个问题吗?我不确定在哪里寻找问题,也许有人可以推动我朝着正确的方向前进?
提前致谢!
【问题讨论】:
-
您可能遇到了速率限制器,而 google 正在扼杀您的访问权限。要么你打谷歌的次数太多(例如每封电子邮件一次),要么你在特定时间内发送了太多次。
-
当您编写这样的邮件脚本时,您可能希望考虑使用专门从事此类服务的交易电子邮件提供商之一。
标签: php email ssl zend-framework2 smtp