ebe*_*dez 13 swiftmailer laravel laravel-4
我正在使用Laravel 4中的新邮件类,有人知道如何检查电子邮件是否已发送?至少邮件已成功移交给MTA ......
Ant*_*iro 11
如果你这样做
if ( ! Mail::send(array('text' => 'view'), $data, $callback) )
{
return View::make('errors.sendMail');
}
Run Code Online (Sandbox Code Playgroud)
你会知道它何时被发送,但它可能会更好,因为SwiftMailer知道收件人失败了,但是Laravel没有暴露相关参数来帮助我们获取这些信息:
/**
* Send the given Message like it would be sent in a mail client.
*
* All recipients (with the exception of Bcc) will be able to see the other
* recipients this message was sent to.
*
* Recipient/sender data will be retrieved from the Message object.
*
* The return value is the number of recipients who were accepted for
* delivery.
*
* @param Swift_Mime_Message $message
* @param array $failedRecipients An array of failures by-reference
*
* @return integer
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$failedRecipients = (array) $failedRecipients;
if (!$this->_transport->isStarted()) {
$this->_transport->start();
}
$sent = 0;
try {
$sent = $this->_transport->send($message, $failedRecipients);
} catch (Swift_RfcComplianceException $e) {
foreach ($message->getTo() as $address => $name) {
$failedRecipients[] = $address;
}
}
return $sent;
}
Run Code Online (Sandbox Code Playgroud)
但是您可以扩展Laravel的Mailer并将该功能($ failedRecipients)添加到新类的方法发送中.
编辑
在4.1中,您现在可以使用访问失败的收件人
Mail::failures();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9759 次 |
| 最近记录: |