【发布时间】:2016-11-24 12:38:34
【问题描述】:
我在使用 Exim 4.87 的服务器上有一个 PHPMailer 5.2.16,它也有一个用于安全连接的 TLS 证书。
我的 PHP 是这样的:
class MailerSMTP extends PHPMailer {
/***
* Mailer for authenticated SMTP emails using account mail system
***/
public function __construct(){
$this->AddReplyTo('...', '...');
$this->setFrom('...', '...');
$this->Host = "hostname.co.uk";
$this->isSMTP();
$this->Timeout = 20;
$this->SMTPAuth = true;
$this->SMTPSecure = "tls";
$this->Port = "587";
$this->Username = 'emailuser';
$this->Password = 'emailpass';
}
}
这显然是在脚本上调用的,并填充了接收者和消息等。
但是,SMTPSecure 方面会在发送消息所用的时间上增加大约 2 秒(或有时更多)。目前,此延迟发生在单条消息发送上,我希望希望(我想我在某处读过)只需调用一次 SMTP 安全功能即可将 X 条消息发送给 X 条收件人.
- 虽然我接受这种延迟可能在某种程度上是不可避免的,但我想就如何通过这种方法提高安全 SMTP 的效率提出一些建议?
额外问题:
- 无论通过它发送的电子邮件数量如何,我认为这种延迟只会在实例化此类时发生一次,这是否正确?
我想我可以做这样的事情:
$sender = new MailerSMTP();
$sender->subject ="hello";
$sender->Body = "message";
foreach($receiver as $row){
$sender->addAddress($row['email']);
$sender->send();
$sender->clearAddresses();
}
这是否会以 2 秒 SMTPSecure 延迟发送所有电子邮件?
【问题讨论】: