I want to change the email sender's address when I send the mail in my application. The new email address is the address of the login user,I don't want the address from the configuration file (mail.php).
How can I change it? I cannot find any relation online solution. Please help !
This is my mail.php file:
array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => "test@gmail.com", 'name' => "Jasmin"),
'encryption' => 'ssl',
'username' => "jasmin.test12@gmail.com",
'password' => "*********",
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
And this is in my controller:
Mail::send('view.view1', $data, function($message) use ($data)
{
$message->from($data['from'], 'Hello world!');
$message->to($data['to'])->subject($data['object']);
});
When I run, mail is always sent from : "jasmin.test12@gmail.com" which is the username in the cofiguration file (mail.php). The email address of the sender should be from $data['from'] where I defined here :
$message->from($data['from'], 'Hello world!');
Note**: All elements in the array of $data is fine.
I use gmail as smtp service.
Try to config with your own mail server then try to set difference sender email address to test send an email. It may work properly.
This is not a laravel issue, google doesn't send your E-Mail with a different email address unless you have verified the sender email address.
You can read here how to set up your email account for sending with google.
Or, do yourself a favour and use a smtp provider with less restrictions, such as mandrill. Mandrill is fully supported by laravel and let's you send 12.000 emails per month for free.