Nicolas
Nicolas

Reputation: 4756

Mailgun emails not going out

I'm creating a verification email, however the mail isn't going out and I don't receive any errors.

My call to send the email:

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());
}

here's my email build function:

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,
                ]);
}

I installed guzzlehttp/guzzle

and changed my files:

ENV (not sure of the port setting)

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=Default mailgun sandbox Password
MAIL_ENCRYPTION=tls

config/services

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

config/mail

<?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', '[email protected]'),
        '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'),
        ],
    ],

];

I don't receive any errors, however there are no outgoing mails when I check the mailgun dashboard

Upvotes: 0

Views: 394

Answers (1)

Joel Hinz
Joel Hinz

Reputation: 25374

Your services config file is wrong:

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

You're trying to look up the values from the .env file here. Should reference the keys, not the values. For instance:

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

And then add them to your .env file:

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

I'm assuming the rest is correct but I don't know for certain. :)

Upvotes: 2

Related Questions