Getting error while trying to send email in localhost php-ThrowExceptions

Exception or error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

app.php

'EmailTransport' => [
    'default' => [
        //**'className' => MailTransport::class,
        /*
         * The following keys are used in SMTP transports:
         */
        'host' => 'ssl://smtp.gmail.com',
        'port' => 567,
        //'timeout' => 30,
        'username' => 'abc@gmail.com',
        'password' => 'abc',
        'className' => 'Smtp',
       // 'client' => null,
        'tls' => true,
        //'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],


'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'abc@gmail.com',

    ],
],

Controller class

 public function mail()
    {
        $session = $this->request->session();
        $id = $session->read('req_id');
        $email = new Email();
        $email->transport('default');
        $email->from(['NO-REPLY.formcr1@abc.com.au' => 'abc REPLY']);
        $email->sender(['NO-REPLY.formcr1@abc.com.au' => 'abc NO-REPLY']);
        $email->to('abc@gmail.com'); /** This must be changed to abc's confirmed email */
        $email->subject('abc Request Number : '.$id);

        //THIS PATH NEEDS TO BE CHANGED DURING DEPLOYMENT
        $path = 'C:/xampp/htdocs/request_form/webroot/pdfresults/';
        $email->attachments($path. 'abc Cost Estimate Request Information_'.$id.'_'.'v.3online'.'.pdf');

        $email->send('Please look for the attachment to see the form. Cheers!');
    }

enter image description here

email credential are correct. and tried turning off the firewalls as well but still not working

enter image description here

How to solve:

The error means exactly what it says – the service you’re trying to connect to doesn’t exist or is not responding.

This is explained two ways. Either the service you’re connecting to is indeed down, or you’re trying to connect to the wrong server or port.

In this case, it’s the latter. You’re trying to connect to an implicit TLS SMTP service on a port not associated with that service.

Change this:

'host' => 'ssl://smtp.gmail.com',
        'port' => 567,

To

'host' => 'ssl://smtp.gmail.com',
        'port' => 465,

Or

'host' => 'tls://smtp.gmail.com',
        'port' => 587,

Leave a Reply

Your email address will not be published. Required fields are marked *