Reputation: 13
This is my code:
Mail::send('view',$dataView, function($message) use ($user)
{
$message->from('[email protected]', 'Myname');
$message->subject('This is title');
$message->to([email protected], $user->user_username);
});
It works! But When I check [email protected] then I see "from email" which I config in .env ( MAIL_USERNAME ), it isn't "from email" in code ([email protected]), How to I can change it to [email protected]? Thanks and sorry about my english.
Upvotes: 1
Views: 311
Reputation: 2282
In config/mail.php
, around line 58, try changing:
'from' => [
'address' => '[email protected]',
'name' => 'Example',
],
to:
'from' => [
'address' => env('MAIL_USERNAME'),
'name' => env('MAIL_USERNAME')
],
Upvotes: 1
Reputation: 5099
I guess you're misunderstanding the MAIL_USERNAME
which is in your .env
file.
So basically, Laravel provides simple solution to send emails via dynamic senders. Lets say you've signed up for MailGun or SendGrid to send mails and MAIL_USERNAME
is the username for your mail provider not your sender
mail address. (Not Gmail, as Gmail doesn't support dynamic senders. Its good if you're testing your mails.).
so, you're .env
will look like this.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=sendgridUsername
MAIL_PASSWORD=sendgridPassword
MAIL_ENCRYPTION=tls
Now, you're eligible to send mails using sendgrid. Now Lets say your domain is example.com
so you can use [email protected]
support@example
or any email address with your domain to send emails.
To Receive messages either you use webmail or Gmail.
Hope this helps.
Upvotes: 0
Reputation: 1497
You are trying to send emails via dynamic senders which is not allowed by Gmail
for preventing spamming mails, so automatically Gmail
will change your sender address to your default address.
Upvotes: 0