How to fix "Cannot send message without a sender address" - Laravel
1 min read

How to fix "Cannot send message without a sender address" - Laravel

A lots of time when we start a new laravel application we forget to setup the mail driver. And then, when we try to send an email it will fail.

When mail driver it is not configured, a "Swift_TransportException" will be thrown.

To fix it, we just need to configure a mail driver. Laravel offers a variety of drivers options like "smtp", "sendmail", "mailgun", "ses", "postmark", "log", "array".

Configure Mail Driver

Today we will learn how to configure mail driver using mailtrap.

Mailtrap is a self email testing for staging and development, where you can inspect and debug your email samples before delivering them to your customers.

So open your .env file. Here you will see the default configuration variables:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

You need to have an account on mailtrap.io.

On mailtrap go to your "inbox > settings", there you will see your "Credentials".

[SOLVED] Cannot send message without a sender address - maitrap dashboard

On your inbox settings page select "Laravel" as your integration.

Copy the variables provided by mailtrap and update your environment file.

[SOLVED] Cannot send message without a sender address - maitrap inbox settings

Finally you just need to choose a "from email adress".

MAIL_FROM_ADDRESS=no-reply@myemail.com

Our final .env variables:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=someUsername
MAIL_PASSWORD=yourPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=no-reply@myemail.com
MAIL_FROM_NAME="${APP_NAME}"

To finish, just clear the cache of your config file:

php artisan config:clear

Enjoying these posts? Subscribe for more