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 "noreply@mydomain.net". 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.
Paul Lucero
  • 547
  • 4
  • 8
  • 15

2 Answers2

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
Edwin Thomas
  • 1,186
  • 2
  • 18
  • 31
  • not working my case MAIL_DRIVER=smtp MAIL_HOST=smtp.googlemail.com MAIL_PORT=465 MAIL_USERNAME=xxxxxxx@xxxxx.com MAIL_PASSWORD=xxxxxxxx MAIL_ENCRYPTION=ssl MAIL_FROM_ADDRESS=xxxxxx@xxxxx.com – MH Fuad Feb 24 '20 at 13:28
  • @MHFuad did you run the command, php artisan config:cache – Edwin Thomas Jun 27 '20 at 09:01
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('noreply@mydomain.net', 'Your application title');
            $message->to('yourcustomer@yourdomain.com');
        });

or use send function

Mail::send('emails.admin.member', $data, function($message) {
            $message->subject("A new Member has been Registered" );
            $message->from('noreply@mydomain.net', 'Your application title');
            $message->to('yourcustomer@yourdomain.com');
        });

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..

Mohamed Akram
  • 2,244
  • 15
  • 23