Mail configuration in laravel 5

In Laravel 5, mail configuration need to be done in .env file and mail.php files. In one of our projects, we have used the thrid
party mail server ‘mailgun’ for sending mail.

In .env file:

 

MAIL_DRIVER=sendmail
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=YOUR USERNAME
MAIL_PASSWORD=YOUR PASSWORD
MAIL_ENCRYPTION=tls

 

In the above configuration, the issue which we have faced was ‘mail driver’. Initially, it was ‘SMTP’ and then after lot of attempts,
we have used ‘sendmail’ as mail driver and it was worked ( Note: we have used godaddy hosting).

Once we configure the .env file and we need to add the same details in ‘config/mail.php’ file with additional information such as ‘from’ email address

In config/mail.php

 

return [

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'notification@chatur.phpgainers.com', 'name' => "Chatur"],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('postmaster@sandboxb76807a698754f1dbb01e4bd7c46e80f.mailgun.org'),
'password' => env('55098439658e30bb9956e6124c5cafe5'),
];

Note:

you need to make sure that ‘ from email address’ should have domain name where you have hosted your application. For example: your website name is www.example.com. then
your from mail address may be ‘notify@example.com’ or ‘contact@example.com’ and it should not be like ‘contact@someotherwebsite.com

Related posts