I recently upgraded my Laravel from 5.7.29 to 8.51. I have been using the Mailgun API to send emails for years. The old version of the site is still able to send via mailgun, but the new version keeps returning this message:
Client error: `POST https://api.mailgun.net/v3/mg.clstracking.com/messages.mime` resulted in a `401 Unauthorized` response: Forbidden
I found similar posts that indicate that kind of response if you're working in the EU and fail to change the MAILGUN_ENDPOINT in the services config. The server and site are all in the USA. I have verified I have the correct settings in my .env and that those are passed into my services.php config file and cached using artisan config:cache. I verified this by looking through the /bootstrap/cache/config.php and everything is there - I even checked this against another site with a different domain that is working the same way. I even tried hard-coding my domain and secret into the services.php.
If I change
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
with my username and password, I get no error, but the email isn't sent and checking the logs on mailgun, there is no record. I'm at a loss what else to try.
In env I have:
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=mg.mydomain.com
MAILGUN_SECRET=key-##########################
In config/services.php:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
In config/mail.php:
'default' => env('MAIL_MAILER', 'mailgun'),
'mailers' => [
'mailgun' => [
'transport' => 'mailgun',
],
],