Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

khryshchuk's avatar

Laravel 11 + mailgun

Hi. Please help me. When I try to send Email with Mailgun by instruction https://laravel.com/docs/11.x/mail#mailgun-driver - I get error: "Could not reach the remote Mailgun server." - https://prnt.sc/JzAl88lGpJVU

File config/mail.php

...
'mailers' => [
    'mailgun' => [
        'transport' => 'mailgun',
    ],
....
],

File config/services.php

...
'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
        'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
        'scheme' => 'https',
    ],
...

File .env

MAIL_MAILER=mailgun
MAILGUN_DOMAIN=mailgun-domain.com
MAILGUN_SECRET=secret-api-code
MAILGUN_ENDPOINT=smtp.eu.mailgun.org

How I can fix this error?

0 likes
2 replies
khryshchuk's avatar

After change variable MAILGUN_ENDPOINT in .env to:

MAILGUN_ENDPOINT=api.mailgun.net

Now error has changed

 Unable to send an email: Forbidden (code 401). 

How to fix this error?

khryshchuk's avatar

Got it all figured out. The matter is closed. The problem was that the MAILGUN_ENDPOINT variable in the .env file had to be set with “eu”:

MAILGUN_ENDPOINT=api.eu.mailgun.net

Also, in this file it was necessary to set the MAIL_FROM_ADDRESS variable where to specify Email in the domain, which is the same as the site:

[email protected]

Please or to participate in this conversation.