简体   繁体   English

尝试在 localhost php 中发送电子邮件时出错

[英]Getting error while trying to send email in localhost php

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应用程序.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并尝试关闭防火墙,但仍然无法正常工作

在此处输入图片说明

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.您正尝试在与该服务无关的端口上连接到隐式 TLS SMTP 服务。

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,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM