Getting User is not set using mailgun in Laravel 10

163 Views Asked by At

I'm trying to setup mailgun in Laravel 10 using the Mailgun API. The mail is using the laravel queue. When the queue tries to send the email I receive this error:

production.ERROR: User is not set. {"exception":"[object] (Symfony\\Component\\Mailer\\Exception\\IncompleteDsnException(code: 0): User is not set. at /var...../class/releases/20231124151624/vendor/symfony/mailer/Transport/AbstractTransportFactory.php:44)

Because I use the API my .env looks like this:

MAIL_MAILER=mailgun
MAILGUN_DOMAIN=mg.*****.nl
MAILGUN_SECRET=afb*****
MAILGUN_ENDPOINT=api.eu.mailgun.net

Ik I use these settings on my development machine everything works, but on the production server, I get the "user not set" error. I tried using the API in a curl command on the server, this also works fine:

curl -s --user 'api:afb***' \
    https://api.eu.mailgun.net/v3/mg.***.nl/messages \
    -F from='Excited User <mailgun@mg.***.nl>' \
    -F to=****@gmail.com \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomeness!'

(example from mailgun docs) Laravel config as instructed in Laravel DOC: mail.php

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

and services.php

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

to make sure I cleared all caching on the server (better one too many than not enough)

    php artisan clear-compiled
    php artisan cache:clear
    php artisan view:clear
    php artisan config:clear
    php artisan route:clear
    php artisan optimize:clear

    composer dump-autoload
    composer clear-cache

and I restarted apache but nothing seems to work. Because it works fine on my local machine, I think the code must be OK. But I am at a loss what else to try. Please help!

0

There are 0 best solutions below