Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail from local machine using laravel

I want to send mail from my local machine using laravel 5.4 in a forget password API. But I am getting Swift_TransportException

(1/1) Swift_TransportException
Expected response code 220 but got code "502", with message "502 Command not implemented
"


The .env details is

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME=Project.com


The code I am getting error is

$response = $this->broker()->sendResetLink(
      $request->only('email')
);


The code in config/mail.php is

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'markdown' => [
        'theme' => 'default',

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

How can I enable mailing from my local machine? Does I have to enable port for that?

like image 986
Salini L Avatar asked Jul 14 '17 11:07

Salini L


People also ask

Can we send mail from localhost in laravel?

Laravel provides drivers for SMTP, Mailgun, Mandrill, SparkPost, Amazon SES, PHP's mail function, and sendmail , allowing you to quickly get started sending mail through a local or cloud based service of your choice.


Video Answer


2 Answers

You can download and use fakesmtp http://nilhcem.com/FakeSMTP/ for localhost and set port :25 by default..for any framework its support for local server machines . Only you need to start whenever you want send mail and check the mails log in fakesmtp.

like image 170
Devraj Gupta Avatar answered Oct 19 '22 10:10

Devraj Gupta


Just a thought:

Try use mailtrap.io on local development machine. It's easy to configure and laravel supports it out of the box. Shouldn't bother your production mail server during development.

Cheers!

like image 1
Zeshan Avatar answered Oct 19 '22 10:10

Zeshan