简体   繁体   中英

Can only send email to myself using Laravel 5 and Mailgun

I've been able to successfully send an email to myself using a combination of Laravel 5 and Mailgun but I am getting a frustrating "bad request" error when I try to change just one line of the code. Specifically, when I change this line:

$message->to('xxx@mydomain.com') to an email that is not the one used by my Mailgun account, I get a bad request error. That is the only thing I am changing.

Edit (here is my code):

Mail::send('emails.alerts.assess_tomorrow', $view_data, function($message) {
$message->to('xxx@mydomain.com')->subject('test 23')->from('xxx@mydomain.com');
            });

Edit2 (my mail.php code):

<?php

return [

        'driver' => 'mailgun',
        'host' => 'smtp.mailgun.org',
        'port' => 587,
        'from' => ['address' => 'xxx@mydomain.com', 'name' => 'A Name'],
    'encryption' => 'tls',
        'username' => 'my mailgun postmaster username',
        'password' => 'my mailgun password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

I have installed Guzzle and updated laravel. As I mentioned, this works perfectly when the "to" email is to myself (the address used by my mailgun account).

In other words, I can only send an email to myself. So I know the code is basically working, but it seems changing the "to" address (for example to my gmail address), results in the bad request error.

Am I missing something obvious? Many thanks for any ideas!

SOLVED! What a maroon I am. I didn't notice that my mailgun account needed to be verified before I could send an email to other addresses.

I logged into mailgun and resent the activation email. After the account was activated, everything worked perfectly. Sorry to take up your time but perhaps this might help other wayward folks!

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