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.