简体   繁体   中英

Laravel Sending Emails with Mailgun

Trying to follow the documentation ( http://itsolutionstuff.com/post/mailgun-setup-with-laravel-5-exampleexample.html and https://laravel.com/docs/5.2/mail ) to get my laravel instance to send emails using Mailgun. Seems to work, from the contact page, because it redirects itself to the contact page, but the email never seems to be sent. Mailgun is also not registering that it sent an email.

From Mailgun, the domain has already been verified and DNS for TXT values have been setup.

Using Laravel 5.4

    Mail::send('emails.contactEmail', ['header' => $headers], function($message) {
        $message->from('info@domainname.com', 'Info Header');
        $message->to('personalemailfortest@gmail.com');

    });

.env file is setup like so:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@mg.domainname.com
MAIL_PASSWORD=1****************************8
MAIL_ENCRYPTION=tls

services.php

   'mailgun' => [
        'domain' => env('mg.domainname.com'),
        'secret' => env('key-f**************************e'),
    ],

No error messages anywhere in console or laravel.log. Not sure where things are breaking down. Not even sure how to begin troubleshooting this issue.

Did you write your credit card credentials when register your account?

Accounts without a credit card are restricted to authorized recipients only.

Authorized Recipients

EDIT Try this solution

MAIL_DRIVER=mailgun
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAILGUN_DOMAIN=your_verified_domain
MAILGUN_SECRET=your_secret_key

Copy/past my own .env which work perfectly :)

In config/services :

'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

In config/mail :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM