Reputation: 1046
I use Laravel 5.1 and want to send the admin of the page a mail with the content of a contact form.
In my .env file I added the following lines:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=adminpassword
MAIL_ENCRYPTION=tls
In my controller I have the following:
Mail::send('Site::email', ['contactObject' => $contactObject], function ($message) use ($contactObject) {
$message->from($contactObject->email, $contactObject->vorname)->subject('New contact!');
$message->to('[email protected]');
});
$contactObject == contains the form which was filled out in the form from the user
Desired result: When [email protected] receive a email, the sender of the mail should be $contactObject->email
Actual result: When [email protected] receive a email, the sender of the mail is [email protected]
Any ideas what goes wrong? Thank you
Upvotes: 0
Views: 2292
Reputation: 11267
You have to just use in .env file:
MAIL_DRIVER=mail
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
After change in .env file, restart service, or use command php artisan config:cache and php artisan config:clear.
Upvotes: 1
Reputation: 1316
Try This:
In Live server you have no need to configure any type of mail service.
You have to just use this:
MAIL_DRIVER=mail
AND remove this code:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=adminpassword
MAIL_ENCRYPTION=tls
Upvotes: 1
Reputation: 6301
Have you configured the global from address in the config?
Specifically here: https://github.com/laravel/laravel/blob/master/config/mail.php#L49
Chances are that you've set that and it's just using that, making these values blank should let you override it.
Failing that, because you're using Gmail to send an email to Gmail, it's likely not letting you spoof the from and is indeed a security feature on their end.
Upvotes: 0