I’m working on a Laravel 9 project and trying to set up Mailgun for sending emails. However, every time I attempt to send an email, I get this error message:
Symfony\Component\Mailer\Exception\HttpTransportException: Unable to send an email: 404 page not found
Here’s my current configuration:
Environment variables (.env file):
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=my-domain-here
MAILGUN_SECRET=my-secret-key
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_ENCRYPTION=tls
Configuration in config/mail.php:
'default' => env('MAIL_MAILER', 'mailgun'),
Settings in config/services.php:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
I’ve double-checked my Mailgun credentials and they seem correct. Has anyone encountered this issue before? What could be causing this 404 error?
I experienced a similar 404 issue previously. It often stems from a mismatch in the Mailgun endpoint or domain settings. Ensure your MAILGUN_DOMAIN in the .env file matches the exact subdomain listed in your Mailgun account. If you’re utilizing European servers, replacing the endpoint with api.eu.mailgun.net is essential. Additionally, confirm that your MAILGUN_SECRET includes the ‘key-’ prefix. After any changes, remember to run php artisan config:clear to refresh your configuration.
Had the same issue with Mailgun and Laravel. That 404 usually means you’re using the wrong endpoint for your region. If you’re on the Europe servers, update your .env file: MAILGUN_ENDPOINT=api.eu.mailgun.net. Also double-check that MAILGUN_DOMAIN matches exactly what’s in your Mailgun dashboard. Don’t forget to run php artisan config:clear after making changes. Fixed it for me right away.
check your mailgun domain setup - you might be usin the full domain instead of the subdomain. if your domain’s mg.yoursite.com, put that in MAILGUN_DOMAIN, not yoursite.com. also make sure your mailgun accnt’s verified and not stuck in sandbox mode, which causes weird 404s.