How to use cPanel email accounts to send confirmation emails in laravel?
Asked Answered
E

2

8

I have uploaded my laravel project onto the production server. Locally, I was using my personal gmail account to send confirmation emails to new users. Since I've uploaded it already, I created an email account in cpanel "[email protected]". How do I use this in my Laravel project?

  1. Can I use this to send email confirmations to new users? Or do I need to create another service provider like Mandrill or Mailchimp?
  2. If I can use this, what is the settings? Sorry I'm very new.
Elisaelisabet answered 26/7, 2016 at 23:39 Comment(0)
R
9

In .env file add following details

MAIL_DRIVER=smtp
MAIL_HOST=your_host
MAIL_PORT=your_port
MAIL_USERNAME=your_mail_username
MAIL_PASSWORD=your_mail_password
MAIL_ENCRYPTION=your_encryption
Rebutter answered 27/7, 2016 at 7:25 Comment(2)
not working my case MAIL_DRIVER=smtp MAIL_HOST=smtp.googlemail.com MAIL_PORT=465 [email protected] MAIL_PASSWORD=xxxxxxxx MAIL_ENCRYPTION=ssl [email protected]Dorotea
@MHFuad did you run the command, php artisan config:cacheRebutter
B
3

open config/mail.php, .env files and set your email driver as mail as bellow,

'driver' => env('MAIL_DRIVER', 'mail'), //you must set it in env file too

then you can send emails like bellow, note that emails.admin.member, is the path to your email template, in the example code, laravel will look for a blade template in the path, resources\views\emails\admin\member.blade.php

Mail::queue('emails.admin.member', $data, function($message) {
            $message->subject("A new Member has been Registered" );
            $message->from('[email protected]', 'Your application title');
            $message->to('[email protected]');
        });

or use send function

Mail::send('emails.admin.member', $data, function($message) {
            $message->subject("A new Member has been Registered" );
            $message->from('[email protected]', 'Your application title');
            $message->to('[email protected]');
        });

the difference between them is, if you have a performance concern, go for queue method and it will send the emails in the background process without waiting to process the script, send function will wait until the emails be sent to continue the script..

Brunt answered 27/7, 2016 at 7:15 Comment(1)
Thanks a lot. Just setting the driver to 'mail' worked for me.Dogmatic

© 2022 - 2024 — McMap. All rights reserved.