我正在使用 PHPMailer 发送电子邮件,效果很好。但问题是,由于它同步发送电子邮件,因此后续页面加载需要很长时间。
我正在使用 PhpMailer,如本示例所示https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
我想知道是否有办法使电子邮件发送异步。我对此进行了研究,发现 sendmail 有一个选项可以将 DeliveryMode 设置为“后台模式” - 来源http://php.net/manual/en/function.mail.php 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 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/ http://blog.oneiroi.co.uk/linux/php/php-mail-making-it-not-suck-using-sendmail/
我更愿意将其作为 api 调用与 php.ini 的内联参数来执行,这样这不是全局更改。有人试过这个吗?