Mailgun电子邮件没有出去

时间:2017-06-08 20:39:45

标签: php laravel email laravel-5.4 mailgun

我创建了一封验证邮件,但是邮件没有出去,我也没有收到任何错误。

我打电话发送电子邮件:

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    event(new Registered($user = $this->create($request->all())));

    Mail::to($user->email)
        ->queue(new VerifyEmail($user));

    return $this->registered($request, $user)
                    ?: redirect($this->redirectPath());
}

这是我的电子邮件构建功能:

public function build()
{
    return $this->view('emails.account.verify_email')
                ->with([
                    'id' => $this->user->id,
                    'firstname' => $this->user->firstname,
                    'token' => $this->user->email_verification_token,
                ]);
}

我安装了guzzlehttp/guzzle

并更改了我的文件:

ENV(不确定端口设置)

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@sandbox...655.mailgun.org
MAIL_PASSWORD=Default mailgun sandbox Password
MAIL_ENCRYPTION=tls

配置/服务

'mailgun' => [
    'domain' => env('sandbox...655.mailgun.org'),
    'secret' => env('key-...'),
],

配置/邮件

<?php

return [

    'driver' => env('MAIL_DRIVER', 'mailgun'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

我没有收到任何错误,但是当我检查mailgun仪表板时没有外发邮件

1 个答案:

答案 0 :(得分:2)

您的服务配置文件错误:

'mailgun' => [
    'domain' => env('sandbox...655.mailgun.org'),
    'secret' => env('key-...'),
],

您正在尝试在此处查找.env文件中的值。应该引用键,而不是值。例如:

'mailgun' => [
    'domain' => env('MAIL_DOMAIN'),
    'secret' => env('MAIL_SECRET'),
],

然后将它们添加到.env文件中:

MAIL_DOMAIN=sandbox...655.mailgun.org
MAIL_KEY=key-...

我假设其余的都是正确的,但我不确定。 :)