Laravel 4邮件类,如何知道电子邮件是否已发送? [英] Laravel 4 mail class, how to know if the email was sent?

查看:94
本文介绍了Laravel 4邮件类,如何知道电子邮件是否已发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 4中使用新的邮件类,有人知道如何检查电子邮件是否已发送吗?至少该邮件已成功移交给MTA ...

I'm using the new mail class in Laravel 4, does anybody know how to check if the email was sent? At least that the mail was successfully handed over to the MTA...

推荐答案

如果这样做

if ( ! Mail::send(array('text' => 'view'), $data, $callback) )
{
   return View::make('errors.sendMail');
}

您会知道何时发送或不发送它,但这可能会更好,因为SwiftMailer知道会将失败发送给收件人,但是Laravel不会公开相关参数来帮助我们获取该信息:

You will know when it was sent or not, but it could be better, because SwiftMailer knows to wich recipients it failed, but Laravel is not exposing the related parameter to help us get that information:

/**
 * 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;
}

但是您可以扩展Laravel的Mailer并将该功能($ failedRecipients)添加到新类的send方法中.

But you can extend Laravel's Mailer and add that functionality ($failedRecipients) to the method send of your new class.

编辑

在4.1中,您现在可以使用

In 4.1 you can now have access to failed recipients using

Mail::failures();

这篇关于Laravel 4邮件类,如何知道电子邮件是否已发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆