killerbeast2017's avatar

Mailgun configuration help

I created a Mail Gun account and using Laravel 5.3.10. I changed my private key and domain in config/services.php . In the .env file, I have the following code:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAILGUN_DOMAIN=xxx.mailgun.org
MAILGUN_SECRET=xxx

What do I need to change to make the mailings work?

0 likes
15 replies
mstnorris's avatar

You need to change your driver.

MAIL_DRIVER=mailgun

The other two just use your own settings which I'm sure you've done.

MAILGUN_DOMAIN=xxx.mailgun.org
MAILGUN_SECRET=xxx

That's it :)

1 like
killerbeast2017's avatar

@mstnorris I had this in my .env file :

MAIL_DRIVER=smtp
MAIL_HOST=mailgun
MAIL_PORT=587
MAIL_USERNAME=postmaster@sandboxcd***.mailgun.org
MAIL_PASSWORD=e***3
MAIL_ENCRYPTION=null
MAILGUN_DOMAIN=sandboxcd***.mailgun.org
MAILGUN_SECRET=key-***e

and in my services.php :

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

But I get something like this :

1/1 Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host mailgun [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]
in StreamBuffer.php line 269
at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62
at Swift_Transport_StreamBuffer->initialize(array('protocol' => '', 'host' => 'mailgun', 'port' => '2525', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
mstnorris's avatar

You haven't set the MAIL_DRIVER as I said.

Currently you're setting the MAIL_HOST, they aren't the same!

mstnorris's avatar

Leave it out, you don't need it as you're letting Mailgun take care of it :)

Lars-Janssen's avatar

@yeshwanthvshenoy I understand that. But if I look into mailgun I only see:

State
Active
IP Address
SMTP Hostname
Default SMTP Login
Default Password
API Base URL
API Key
killerbeast2017's avatar

@lars64 have a look in your here : https://mailgun.com/app/dashboard . If you scroll down to the bottom, there will be something like public api key and secret api key. That would be the secret key you need to provide. In your answer's list, the last one API key is the same as I am referring to.

killerbeast2017's avatar

@mstnorris No brother it seems curl needs some sort of SSL certificate to send mails. First it seemed to complain about lack of curl on my machine. I installed it now it says SSL is missing.

mstnorris's avatar

Please answer the following:

  1. What OS are you using: Windows 7, 8 etc, macOS?
  2. Are you using Laravel Homestead? I think I saw you mention earlier that you're using WAMP
  3. What is the exact error message you're receiving?
killerbeast2017's avatar

@mstnorris

OS is Windows 10. Yes, WAMP. The full error would be:

 1/1 RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

in CurlFactory.php line 187
at CurlFactory::createRejection(object(EasyHandle), array('errno' => '60', 'error' => 'SSL certificate problem: unable to get local issuer certificate', 'url' => 'https://api.mailgun.net/v3/sandboxcd90ebe7555b4421903e406dd5c46d7f.mailgun.org/messages.mime', 'content_type' => null, 'http_code' => '0', 'header_size' => '0', 'request_size' => '0', 'filetime' => '-1', 'ssl_verify_result' => '1', 'redirect_count' => '0', 'total_time' => '0.734', 'namelookup_time' => '0.062', 'connect_time' => '0.312', 'pretransfer_time' => '0', 'size_upload' => '0', 'size_download' => '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '-1', 'upload_content_length' => '-1', 'starttransfer_time' => '0', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '173.203.37.112', 'certinfo' => array(), 'primary_port' => '443', 'local_ip' => '193.168.4.16', 'local_port' => '53533')) in CurlFactory.php line 150
at CurlFactory::finishError(object(CurlHandler), object(EasyHandle), object(CurlFactory)) in CurlFactory.php line 103
at CurlFactory::finish(object(CurlHandler), object(EasyHandle), object(CurlFactory)) in CurlHandler.php line 43
at CurlHandler->__invoke(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Proxy.php line 28
at Proxy::GuzzleHttp\Handler\{closure}(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Proxy.php line 51
at Proxy::GuzzleHttp\Handler\{closure}(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in PrepareBodyMiddleware.php line 72
at PrepareBodyMiddleware->__invoke(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Middleware.php line 30
at Middleware::GuzzleHttp\{closure}(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in RedirectMiddleware.php line 68
at RedirectMiddleware->__invoke(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Middleware.php line 59
at Middleware::GuzzleHttp\{closure}(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in HandlerStack.php line 67
at HandlerStack->__invoke(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Client.php line 275
at Client->transfer(object(Request), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Client.php line 123
at Client->requestAsync('post', object(Uri), array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <[email protected]> Date: Thu, 29 Sep 2016 11:56:22 +0000 Subject: De-Bug Reset Password! From: [email protected] To: [email protected] MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <h3>Your De-Bug password has been reset to 'VK*^3ej#'. Kindly res= et once you login.</h3> ', 'filename' => 'message.mime')), 'synchronous' => true, 'connect_timeout' => '60', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, '_conditional' => array('User-Agent' => 'GuzzleHttp/6.2.1 curl/7.47.1 PHP/7.0.4'))) in Client.php line 129
at Client->request('post', 'https://api.mailgun.net/v3/sandboxcd90ebe7555b4421903e406dd5c46d7f.mailgun.org/messages.mime', array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <[email protected]> Date: Thu, 29 Sep 2016 11:56:22 +0000 Subject: De-Bug Reset Password! From: [email protected] To: [email protected] MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <h3>Your De-Bug password has been reset to 'VK*^3ej#'. Kindly res= et once you login.</h3> ', 'filename' => 'message.mime')), 'synchronous' => true)) in Client.php line 87
at Client->__call('post', array('https://api.mailgun.net/v3/sandboxcd90ebe7555b4421903e406dd5c46d7f.mailgun.org/messages.mime', array('auth' => array('api', 'key-d1a7a357363d211d7f17ab66774dce8e'), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <[email protected]> Date: Thu, 29 Sep 2016 11:56:22 +0000 Subject: De-Bug Reset Password! From: [email protected] To: [email protected] MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <h3>Your De-Bug password has been reset to 'VK*^3ej#'. Kindly res= et once you login.</h3> ', '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 374
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 196
at Mailer->send('pages.email.passwordreset', array('content' => 'Your De-Bug password has been reset to 'VK*^3ej#'. Kindly reset once you login.', 'message' => object(Message)), object(Closure)) in Facade.php line 237
at Facade::__callStatic('send', array('pages.email.passwordreset', array('content' => 'Your De-Bug password has been reset to 'VK*^3ej#'. Kindly reset once you login.'), object(Closure))) in UserController.php line 114
at UserController->postSubmitResetPassword(object(Request))
at call_user_func_array(array(object(UserController), 'postSubmitResetPassword'), array(object(Request))) in Controller.php line 55
at Controller->callAction('postSubmitResetPassword', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(UserController), 'postSubmitResetPassword') in Route.php line 189
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53

Please or to participate in this conversation.