Sending Email Via Gmail In Laravel - Neuroon Networks

Breaking

Monday, January 14, 2019

Sending Email Via Gmail In Laravel


Open your .env file and you will find below code related to email settings.


MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null



Edit the above details as follows.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=yourEmail
MAIL_PASSWORD=yourEmailPassword
MAIL_ENCRYPTION=tls




For the email You need to Enable IMAP/POP3/SMTP for your Gmail Account. For that


Step 1 Enable IMAP and/or POP3

    Go to the "Settings", e.g. click on the "Gears" icon and select "Settings".
    Click on "Forwarding and POP/IMAP".
    Enable "IMAP Access" and/or "POP Download"

Step 2 Enable Third-Party Mail Clients

    See: https://support.google.com/accounts/answer/6010255?hl=en for details.
    The page contains a link to enable "Less secure apps" in MyAccount.
    You can also enable "Less secure apps" (third-party mail clients) from:    "MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps"


$usere=toSendemail;

$data = array('name'=>'name'); Array to pass data to the Email.
Mail::send('Email/contact', $data, function($message) use($usere) {

 $message->to($usere)->subject('Subject');

 $message->from('From Email','From Name');

});




In the above code, we are using the view ’emails.mail’. It means we have to create folder and files as resources->views->Email->contact.blade.php.


In contact.blade.php will contains html code You want to send.

1 comment: