laravel 5.4: sending email from localhost not working

前端 未结 4 1342
失恋的感觉
失恋的感觉 2020-12-20 20:47

I want to sent emails from my localhost with laravel 5.4. It is showing me the following error: screenshot of the error

This is my .env file

MAIL_DRI         


        
相关标签:
4条回答
  • 2020-12-20 21:23

    I would suggest using the log driver for mail or setting up a mailgun free account but if you really wanna test this from your local dev machine then this answer might help:

    0 讨论(0)
  • 2020-12-20 21:30

    This is a generic windows error when trying to send a mail.

    Try uncommenting extension=php_openssl.dll in php.ini

    0 讨论(0)
  • 2020-12-20 21:31
    Route::get('sendemail', function () {
    
        $data = array(
            'name' => "Learning Laravel",
        );
    
        Mail::send('welcome', $data, function ($message) {
    
            $message->from('ashokchavda193@gmail.com', 'Learning Laravel');
    
            $message->to('ashokchavda193@gmail.com')->subject('Learning Laravel test email');
    
        });
    
        return "Your email has been sent successfully";
    
    });
    
    0 讨论(0)
  • 2020-12-20 21:38

    I had this issue too, this is how i fixed it. Though it is not advisable to change vendor files but this fix worked and it enable me to send mail from my localhost.

    1. Locate StreamBuffer in your vendor folder. It should be in this location

    C:\xampp\htdocs\mylaravel\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport

    1. Open the file StreamBuffer.php
    2. Find this method _establishSocketConnection
    3. Add this as shown below

    $options['ssl']['verify_peer'] = FALSE;

    $options['ssl']['verify_peer_name'] = FALSE;

        private function _establishSocketConnection(){
           ....
    
           $options['ssl']['verify_peer'] = FALSE;
           $options['ssl']['verify_peer_name'] = FALSE;
    
           $streamContext = stream_context_create($options);
           $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
    
        .... }
    

    It's like the ssl keeps preventing the mail from been sent. I hope this helps

    0 讨论(0)
提交回复
热议问题