0

I need to use mail() in laravel project I check this How to configure Laravel mail.php to use built-in mail function? I made as this answer


return [

   
    'driver' => env('MAIL_MAILER', 'sendmail'),

 
    'host' => env('MAIL_HOST', 'smtp.googlemail.com'),

  

    'port' => env('MAIL_PORT', 465),

   
 

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

  
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

  

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

  
 

   // 'sendmail' => '/usr/sbin/sendmail -bs',
    'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail  -t -i'),
    /*
   

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

env


MAIL_MAILER=sendmail
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="${APP_NAME}"

but not work. no mail send to register mail. How can fix it. how can send mail by mail() in laravel

1 Answers1

0

If you want to send emails using gmail's SMTP, sendmail is not what you want to use.

in your .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl

Login to your Google Email Account and click on Google Account Button. This button is display when you click on the profile picture in your Gmail Dashboard as shown.

Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.

After that you can do something like

$to_name = 'RECEIVER_NAME';
$to_email = 'RECEIVER_EMAIL_ADDRESS';
$data = array('name'=>$to_name, 'body' => 'A test mail');
Mail::send('emails.mail', $data, function($message) use ($to_name, $to_email) {
$message->to($to_email, $to_name)
->subject('Laravel Test Mail');
$message->from('SENDER_EMAIL_ADDRESS','Test Mail');
});
Patrick Simard
  • 2,294
  • 3
  • 24
  • 38