【发布时间】:2015-09-24 00:51:19
【问题描述】:
我正在使用 PHPMailer 发送电子邮件,效果很好。然而问题在于,由于它同步发送电子邮件,后续页面加载需要很长时间。
我正在使用 PhpMailer,如本例所示 https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
我想知道是否有办法使电子邮件发送异步。我对此进行了研究,发现 sendmail 可以选择将 DeliveryMode 设置为“后台模式” - 来源 http://php.net/manual/en/function.mail.php
mail($to, $subject, $message, $headers, 'O DeliveryMode=b');
我想知道在 PhpMailer 中是否可以做类似的事情?有人在这方面取得过成功吗?
编辑:-(附加信息) 似乎 PhpMailer 可以配置为使用 sendmail - https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php 因此,我想知道是否可以通过某种方式利用它来启用后台交付。
/**
* Which method to use to send mail.
* Options: "mail", "sendmail", or "smtp".
* @type string
*/
public $Mailer = 'mail';
/**
* The path to the sendmail program.
* @type string
*/
public $Sendmail = '/usr/sbin/sendmail';
/**
* Whether mail() uses a fully sendmail-compatible MTA.
* One which supports sendmail's "-oi -f" options.
* @type boolean
*/
public $UseSendmailOptions = true;
/**
* Send messages using $Sendmail.
* @return void
*/
public function isSendmail()
{
$ini_sendmail_path = ini_get('sendmail_path');
if (!stristr($ini_sendmail_path, 'sendmail')) {
$this->Sendmail = '/usr/sbin/sendmail';
} else {
$this->Sendmail = $ini_sendmail_path;
}
$this->Mailer = 'sendmail';
}
另外 - 显然有办法通过 php.ini 设置 sendmail 选项 http://blog.oneiroi.co.uk/linux/php/php-mail-making-it-not-suck-using-sendmail/
我更愿意将其作为 api 调用与 php.ini 的内联参数来执行,因此这不是全局更改。有人试过吗?
【问题讨论】:
标签: php email asynchronous phpmailer