Reputation: 1068
I have configured my mail.php config file to send emails using the gmail account. Everything looks great, but when I try to send email from another account (not the address used in the mail.php config file) I get an email from the address set on the configuration file.
Mail::send('emails.contact_mail', array(
'email' => $fromEmail,
'name' => $user,
'subject' => $subject,
'message' => $message_content,
), function($message)use ($fromEmail,$user,$subject) {
$message->to('[email protected]');
$message->from('[email protected]', $user);
$message->subject($subject);
});
It seems like the $message->from
doesn't work. I get on the [email protected]
an email from the address set in mail.php
file and not from [email protected]
.
Is there any solution? How to change the from
address?
Upvotes: 3
Views: 4135
Reputation: 41
I think this is best solution for this question. We can figure out this as follows: $message->from('[email protected]', 'sender_name'); And also we should remove the following code block in config/mail.php.
'from' => [
'address' => '[email protected]',
'name' => 'sender_name',
],
of course, this will be working on Laravel Framework.
Upvotes: 1
Reputation: 2272
You will still use the SMTP servers set in your config file. Setting another 'from' header is theoretically possible, but the GMail SMTP will ignore it unless you set an address that has been added to your Google account.
Solution: either don't use another 'from' address, or add that address to your Google account.
Upvotes: 2
Reputation: 76
There are a couple things you can try:
$message->replyTo('[email protected]', $user);
And to my understanding, the "From: " header in emails is what should determine what it will display as the sender. This may work for changing the "From" header:
$message->getHeaders()->addTextHeader('From', 'Your Name <[email protected]>');
Upvotes: 1