Reputation: 614
I've got a contact form that requires a persons Name, Email, Subject and Message in order to send an email. The email successfully sends however the "to" and "from" are from the same email. Here's the controller code:
Mail::send('email-contact',[
'msg' => $request->message
], function ($mail) use ($request) {
$mail->from($request->email, $request->name);
$mail->to('[email protected]')->subject($request->subject);
});
In this case the email sends properly but the "from" field is the same name.
For example I get:
To: "[email protected]", From: "[email protected]".
Instead of:
To: "[email protected]", From: "{the user's email from $request->email}".
What am I doing wrong?
In my .env I have:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls
Upvotes: 0
Views: 626
Reputation: 106
You are using Gmail account for the different identity of the sender you should use your own cpanel SMTP server. Gmail does not provide custom identity.
Upvotes: 1