Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Mail::send()-Laravel 4获取Mandrill消息ID_Php_Laravel_Email_Laravel 4_Mandrill - Fatal编程技术网

Php 如何使用Mail::send()-Laravel 4获取Mandrill消息ID

Php 如何使用Mail::send()-Laravel 4获取Mandrill消息ID,php,laravel,email,laravel-4,mandrill,Php,Laravel,Email,Laravel 4,Mandrill,有没有一种方法可以使用Laravel4中的邮件功能(或任何其他功能)从Mandrill获得响应 使用下面的代码,消息发送良好,但仅返回null: $response = Mail::send('emails.test', [], function($message) { $message->to('test@email.com')->subject('test email'); }); dd($response); 我尝试同时使用smtp驱动程序和Mandrill驱动程

有没有一种方法可以使用Laravel4中的邮件功能(或任何其他功能)从Mandrill获得响应

使用下面的代码,消息发送良好,但仅返回null:

$response = Mail::send('emails.test', [], function($message) 
{
    $message->to('test@email.com')->subject('test email');
});

dd($response);

我尝试同时使用smtp驱动程序和Mandrill驱动程序,但没有任何区别

您似乎无法做到这一点。MandrillTransport::send不返回任何内容,也不公开HttpClient。

在记录从Mandrill sent事件获取
\u id
时也存在一些问题。
为Laravel 5.7创建了一个解决方案

创建CustomMailServiceProvider

<?php
// app/Providers/CustomMailServiceProvider.php

namespace App\Providers;

use App\Misc\Transport\CustomMandrillTransport;
use Swift_Mailer;
use Illuminate\Support\Arr;
use GuzzleHttp\Client as HttpClient;

class CustomMailServiceProvider extends \Illuminate\Mail\MailServiceProvider {

    public function register(){
        parent::register();

        $this->registerMandrillMailer();
    }
    /**
     * Register the CustomMandrill Swift Transport instance.
     *
     * @param  array  $config
     * @return void
     */
    protected function registerMandrillMailer()
    {
        if ($this->app['config']['mail.driver'] == 'mandrill') {
            $this->app->singleton('swift.mailer', function ($app) {
                $mandrillConfig = $app['config']->get('services.mandrill', []);
                return new Swift_Mailer(new CustomMandrillTransport( $this->guzzle($mandrillConfig), $mandrillConfig['secret']));
            });
        }
    }

    /**
     * Get a fresh Guzzle HTTP client instance.
     *
     * @param  array  $config
     * @return \GuzzleHttp\Client
     */
    protected function guzzle($config)
    {
        return new HttpClient(Arr::add(
            $config['guzzle'] ?? [], 'connect_timeout', 60
        ));
    }
}
并添加您自己的:

App\Providers\CustomMailServiceProvider::class,
并确保收听发送的事件

<?php

namespace App\Providers;

use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\SomeEvent' => [
            'App\Listeners\EventListener',
        ],
        'Illuminate\Mail\Events\MessageSent' => [
            'App\Listeners\EmailSentListener',
        ]
    ];
}

那么你知道怎么从Mandrill那里得到消息ID了吗?1。使用MandrillTransport并从中创建您自己的自定义传输,这样它就可以满足您的需要。2.使用Guzzle并自行完成。嘿,我们使用了此功能……但由于某些原因,在我们的本地环境中,它没有接收客户邮件服务提供商,getBody只是返回发送的电子邮件的html。你知道为什么会这样吗?
//        Illuminate\Mail\MailServiceProvider::class,
App\Providers\CustomMailServiceProvider::class,
<?php

namespace App\Providers;

use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\SomeEvent' => [
            'App\Listeners\EventListener',
        ],
        'Illuminate\Mail\Events\MessageSent' => [
            'App\Listeners\EmailSentListener',
        ]
    ];
}