Laravel won't pass my domain to the MailGun driver so I can't send mail

user2929209 picture user2929209 · Dec 9, 2015 · Viewed 7.9k times · Source

This may not be a problem with MailGun as I was unable to send via Gmail aswell.

The error i'm getting as seen below you can see where the domain should be passed but hasn't.

POST https://api.mailgun.net/v3//messages.mime

the domain should be

POST https://api.mailgun.net/v3/domin/messages.mime

I know I have Guzzle installed, I have restated the web server and i know my details are correct. I'v created a test project to do only mail aswell to no avail.

Could it be something todo with my host computer (macbook air) or that fact i'm using the development web server

 php artisan serve

I'm new to Laravel so i'm unsure of anything else I can do.

services.php

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

mail.php

'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
 'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
 'username' => env('postmaster@sandbox***********.mailgun.org'),
  'password' => env('sandboxpassword'),
 'sendmail' => '/usr/sbin/sendmail -bs',
 'pretend' => env('MAIL_PRETEND', false),

A've stopped using the env file so it defaults to the mail.php, but when the attributes are the same details it's the same outcome. And yeah just incase its asked i'm aware you need to restart the server when you've changed the .env and just to be on the safe site i've been doing it when changing the mail.php or services.php

TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    public function index() {
        Mail::raw('Text to e-mail', function ($message) {
            $message->from('[email protected]', 'Laravel');

            $message->to('[email protected]');
        });

        return view('welcome');
    }
}

the exact error

ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND` response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested (truncated...)
in RequestException.php line 107
at RequestException::create(object(Request), object(Response)) in Middleware.php line 65
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run(true) in Promise.php line 240
at Promise->invokeWaitFn() in Promise.php line 217
at Promise->waitIfPending() in Promise.php line 261
at Promise->invokeWaitList() in Promise.php line 219
at Promise->waitIfPending() in Promise.php line 62
at Promise->wait() in Client.php line 129
at Client->request('post', 'https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in Client.php line 87
at Client->__call('post', array('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime'))))) in MailgunTransport.php line 79
at Client->post('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in MailgunTransport.php line 79
at MailgunTransport->send(object(Swift_Message), array()) in Mailer.php line 85
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 181
at Mailer->send(array('raw' => 'Text to e-mail'), array(), object(Closure)) in Mailer.php line 133
at Mailer->raw('Text to e-mail', object(Closure)) in Facade.php line 219
at Facade::__callStatic('raw', array('Text to e-mail', object(Closure))) in TestController.php line 17
at Mail::raw('Text to e-mail', object(Closure)) in TestController.php line 17
at TestController->index()

Answer

kEpEx picture kEpEx · Dec 9, 2015

You need to leave the services.php config as default:

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

Then in the .env you need to put:

MAILGUN_DOMAIN=yourdomain
MAILGUN_SECRET=yoursecret