ashleydw/mail

此包已被废弃,不再维护。没有建议的替代包。

Laravel 4 MailServiceProvider,返回send()的结果

dev-master 2014-08-05 07:42 UTC

This package is not auto-updated.

Last update: 2016-08-30 10:22:21 UTC


README

此包覆盖了默认的Laravel Mail,以返回邮件操作的状态 - Laravel 4.2在v4.2中将所有Mail::send调用返回值更改为void,请参阅:https://github.com/laravel/framework/commit/894752ffb9aab1c65af92acc1ae7004062a2556d,并在https://github.com/laravel/framework/pull/4405#issuecomment-51154875中进行讨论

如果你使用Mandrill或其他需要响应的API,这是不正确的。

此包通过扩展默认的Mail包文件来克服这个问题,并返回正确的响应。它专门为Mandrill构建,但可以轻松添加更多传输方式。

Mandrill使用方法

与之前相同,但现在你可以看到services文件中的选项。例如,要将async属性设置为false(我建议这样做),你的services文件将是:

<?php

return [
    'mandrill' => [
        'secret'   => 'your-secret',
        'options' => [
            'async' => false,
        ]
    ],
];

你可以设置从文档中获取的任何选项(选项只是通过array_merge添加):https://mandrillapp.com/api/docs/messages.JSON.html#method-send

然后,为了获取响应

/** @var \GuzzleHttp\Message\Response $response */
$response = Mail::send(
    $emailTemplate,
    [
        ....
    ],
    function ($message) use ($user, $action) {
        ....
    }
);

/** @var \GuzzleHttp\Stream\Stream $body */
$response = json_decode($response->getBody(), true);

注意:你可能需要检查$response->getStatusCode()