Laravel 5.5 使用 Mailgun 和 Bogardo 设置电子邮件

Laravel 5.5 email setup using Mailgun and Bogardo

我正在尝试使用 Mailgun 在我的 Laravel 5.5 应用程序中设置自动电子邮件通知。我安装了 Mailgun SDK 以及推荐的 Laravel 库 - Bogardo。我使用 Bogardo 库而不是仅仅使用 Mailgun SDK 或内置 Laravel 电子邮件功能的原因是这些都不允许点击跟踪、退回和其他分析功能(我知道)。我可以使用 Tinker 正常发送电子邮件。但是,我不是 100% 确定如何正确调用我的新邮件以这种方式发送电子邮件。这是我的可邮寄 class:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class BaseEmail extends Mailable
{
    use Queueable, SerializesModels;

    /**
    * Create a new message instance.
    *
    * @return void
    */
    public function __construct()
    {
        //
    }

    /**
    * Build the message.
    *
    * @return $this
    */
    public function build()
    {
        $data = ['This is a message from Mailgun!'];

        return Mailgun::raw($data, function($message) {
            $message
                ->to('email@domain.com', 'Name Name')
                ->subject('Yoohoo!')
                ->from('otheremail@domain.com', 'Name')
                ->tag(['tag','tag2']);
        });
    }
}

当我打电话时:

$mail = new App\Mail\BaseEmail();
$mail->send();

我收到以下错误

TypeError: Too few arguments to function Illuminate\Mail\Mailable::send(), 0 passed in /web/vendor/psy/psysh/src/Psy/ExecutionLoop/Loop.php(90) : eval()'d code on line 1 and exactly 1 expected

$mail->send('this');

我明白了

TypeError: Argument 1 passed to Illuminate\Mail\Mailable::send() must be an instance of Illuminate\Contracts\Mail\Mailer, string given on line 1

抱歉,如果这是微不足道的,但我一直在关注他们的文档,并用谷歌搜索了我能想到的所有内容,但没有成功。

任何方向都很棒!

谢谢!

当您使用 raw() 时,您不需要使用 send() 方法。此代码将发送一封电子邮件:

Mailgun::raw($data, function($message) {
    $message->to('email@domain.com', 'Name Name')
            ->subject('Yoohoo!')
            ->from('otheremail@domain.com', 'Name')
            ->tag(['tag','tag2']);
});

您在使用该软件包时也不需要使用 Mailable

Bogardo 包似乎不支持 Laravel Mailables...

https://github.com/Bogardo/Mailgun/issues/72