Reputation: 135
I am creating some booking system and have HTML form in which user enter his email (and other stuff). I would like to get email as if user has send it from his email address, but my Gmail always shows that I have sent it (i.e. sender email address is same as 'username' from app/config/mail.php = [email protected]).
This is Send::mail() method I am using
Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('[email protected]', 'ABC')->subject($data['subject']);
});
This is my app/config/mail.php
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'tls',
'username' => '[email protected]',
'password' => 'XYZ_password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I found out that I could use replyTo
Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('[email protected]', 'ABC')->subject($data['subject']);
$message->replyTo($data['email'], $data['name']); // <--------------------
});
but then I do not know what is the purpose of 'from' field?
Thank you in advance!
Upvotes: 2
Views: 457
Reputation: 359
Maybe you are confuse of the purpose of 'from' and 'replyTo'.
'from' will show to your users where they received email from (It can be set in your Mail::send method in each email or in your app/config/mail.php to apply to all emails).
'replyTo' will define which address that users would send their email to when they click 'reply' button.
Upvotes: 1