Reputation: 149
In my Laravel 5.4 app I want to send an email notification to the user when they signup I have set everything but not work and shown an exception like:
Cannot send message without a sender address
I am using mailtrap.
I have also run the artisan command php artisan config:cache
and php artisan cache:clear
This is my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=3e917ca6b3dabc
MAIL_PASSWORD=05abe282eca67f
MAIL_ENCRYPTION=tls
Upvotes: 8
Views: 13324
Reputation: 201
I think you didn't restart your service. You should restart your service by 2 steps:
Step 1: Stop your service (CMD):
Ctrl + C
Step 2: You run service again:
npm run dev
php artisan serve
Upvotes: 2
Reputation: 342
I ran into the exact same problem with Laravel 6.15.1.
As it turned out, you only need to delete these lines in .env
:
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
Upvotes: 12
Reputation: 10071
In your .env
file you will need to set the email address and password of your email account.
Steps to configure mailtrap:
1) Register to mailtrap: https://mailtrap.io/register/signup
2) Go to Inbox page: https://mailtrap.io/inboxes
3) Click on Demo Inbox link and you will see the following mailtrap smtp credentials, Where the username and password will be something like this:
"username" => "b8f19cb615a7b3",
"password" => "8218011886905f",
Now change to .env
file in the root directory of your project and change the following line:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=***USER NAME***
MAIL_PASSWORD=***PASSWORD***
MAIL_ENCRYPTION=null
After completion of .env
edit please enter this command in your terminal for clear cache:
php artisan config:cache
Upvotes: 2
Reputation:
First of all, check your environment variables in your .env
file.
They should look something like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
Secondly check that you have a mail from address, as your error suggests you cannot send an email without a send address.
config/mail.php
Check for
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
You can set MAIL_FROM_ADDRESS
and MAIL_FROM_NAME
in your .env
file e.g.
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="Example"
If you're using a mailable
You can set who the email is from in your build()
function e.g.
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('[email protected]')
->view('emails.orders.shipped');
}
Upvotes: 1
Reputation:
Please update your .env
file like:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=youremailaddress
MAIL_PASSWORD=gtxajikwsqmlaqc //your app password
Upvotes: 2