For configuring gmail settings in laravel,
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email_address@gmail.com
MAIL_PASSWORD=your_gmail_address_password
MAIL_FROM_ADDRESS=your_email_address@gmail.com
MAIL_FROM_NAME="YOUR_USER_NAME"
MAIL_ENCRYPTION=tls
Also update the following in mail.php
'pretend' => false,
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
To test your configuration put this code on api.php
Route::get('/emailTest',function(){
$emailData = [
'from' => 'admin_email@gmail.com',
'email' => 'user_email@gmail.com',
'password' => 'user_password',
];
// "mails.toUser" : this is my email template in resources
Mail::send('mails.toAdmin',['emailData' => $emailData],function($message) use ($emailData){
$message->to($emailData['email'])
->from($emailData['from'])
->subject('New User Registration');
});
});