Mailgun Email Setup Issue in Laravel - Missing Sender Address Error

I’m working on integrating email functionality into my Laravel application using Mailgun as the email service provider. Everything seems to be configured correctly, but I keep running into this frustrating error:

Swift_TransportException: Cannot send message without a sender address

Here’s my current configuration:

config/mail.php settings:

'mailers' => [
    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'timeout' => null,
    ],
    'mailgun' => [
        'transport' => 'mailgun',
    ],
    'ses' => [
        'transport' => 'ses',
    ],
    'log' => [
        'transport' => 'log',
        'channel' => env('MAIL_LOG_CHANNEL'),
    ],
],

Environment variables (.env):

MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=postmaster@sandbox*****************.mailgun.org
MAIL_PASSWORD=**********************************
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

Mailable class (NotificationEmail.php):

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NotificationEmail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct()
    {
        //
    }

    public function build()
    {
        return $this->from('[email protected]')
                    ->markdown('emails.notification');
    }
}

Email template (notification.blade.php):

@component('mail::message')
# System Alert Notification

ATTENTION: This email is sent because our monitoring system detected an issue that requires immediate attention.

Please click the button below to view the full report.

@component('mail::button', ['url' => ''])
View Report
@endcomponent

Regards,<br>
{{ config('app.name') }}
@endcomponent

Test route:

Route::get('/test-email', function () {
    Mail::to('[email protected]')->send(new NotificationEmail());
    return new NotificationEmail();
});

What am I missing in my configuration? Any help would be appreciated!

Had this exact problem 6 months ago with a client’s Mailgun setup. Your issue is MAIL_FROM_ADDRESS=null in your .env file - that’s what’s throwing the sender address error. Change it to something like [email protected] using your verified Mailgun domain. Since you’re using Mailgun transport, ditch all those SMTP settings. You only need MAILGUN_DOMAIN and MAILGUN_SECRET in your environment variables. After you fix this, run php artisan config:clear and you’re good to go.

check your .env file - you’ve got MAIL_FROM_ADDRESS=null which is literally causing the no sender error. set it to a valid email like [email protected] and make sure that domain’s verified in Mailgun. also run php artisan config:cache after changing it cuz laravel caches config files.

The MAIL_FROM_ADDRESS=null is your main problem, but you’ve got another issue too. Don’t mix transport configs - I made this same mistake migrating from SMTP to Mailgun and it’ll drive you crazy. Since you’re using MAIL_MAILER=mailgun, ditch all the SMTP variables (MAIL_HOST, MAIL_PORT, MAIL_ENCRYPTION, MAIL_USERNAME, MAIL_PASSWORD). Instead, add MAILGUN_DOMAIN=your-domain.com and MAILGUN_SECRET=your-api-key. Also check that your from address in the Mailable matches a verified sender in Mailgun. Spent hours debugging this exact thing because I left the old SMTP stuff mixed in.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.