Connection could not be established with host smpt.qq.com

bug问题 · xiaobeibei · 于 3年前 发布 · 1789 次阅读

注册的提交的时候报这个错误?如何修复在什么位置修复

共收到 15 条回复
Fecmall#13年前 0 个赞

这个是发送邮件的报错(host smpt.qq.com),可以参看地址:fecshop邮件

fecshop的配置文件为:@fecshop/config/services/Email.php ,在这个配置文件里面你可以看到:

// 各个邮件的模板部分:
                'emailTheme' => [
                    // 注册账户发送的邮件的模板配置
                    'register' => [
                        'enable' => true,
                        // 邮件内容的动态数据提供部分
                        'widget'        => 'fecshop\services\email\widgets\customer\account\register\Body',
                        // 邮件内容的view部分
                        'viewPath'        => '@fecshop/services/email/views/customer/account/register',
                        

这个错误是smtp发送邮件导致的,您可以到@common/config/fecshop_local_services/Email.php 中更改smtp为您的smtp配置。

或者将register注册发送邮件功能关掉,具体步骤为:通过配置覆盖的方式,将@fecshop/config/services/Email.php的上面的代码,复制到@common/config/fecshop_local_services/Email.php ,@common的配置在初始化的时候会覆盖@fecshop的配置

@common/config/fecshop_local_services/Email.php

添加前的代码为:

<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 *
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */
return [
    'email' => [
        'mailerConfig' => [
            // 默认通用配置
            'default' => [
                'class'     => 'yii\swiftmailer\Mailer',
                'transport' => [
                    'class'       => 'Swift_SmtpTransport',
                    'host'        => 'smtp.qq.com',            //SMTP Host
                    'username'    => '2420577683@qq.com',   //SMTP 账号
                    'password'    => 'zdveeweuevnldjgd',    //SMTP 密码
                    'port'        => '587',                    //SMTP 端口
                    'encryption'  => 'tls',
                ],
                'messageConfig'=> [
                   'charset'=> 'UTF-8',
                ],
            ],
        ],
    ],
];

添加后的代码为:

<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 *
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */
return [
    'email' => [
        'mailerConfig' => [
            // 默认通用配置
            'default' => [
                'class'     => 'yii\swiftmailer\Mailer',
                'transport' => [
                    'class'       => 'Swift_SmtpTransport',
                    'host'        => 'smtp.qq.com',            //SMTP Host
                    'username'    => '2420577683@qq.com',   //SMTP 账号
                    'password'    => 'zdveeweuevnldjgd',    //SMTP 密码
                    'port'        => '587',                    //SMTP 端口
                    'encryption'  => 'tls',
                ],
                'messageConfig'=> [
                   'charset'=> 'UTF-8',
                ],
            ],
        ],
        
        'childService' => [
            /*
             * 用户中心部分的邮件的设置。
             */
            'customer' => [
                'class' => 'fecshop\services\email\Customer',

                // 各个邮件的模板部分:
                'emailTheme' => [
                    // 注册账户发送的邮件的模板配置
                    'register' => [
                        'enable' => false,
                    ],
                ],
            ],
        ],
    ],
];

关于fecshop配置的原理,可以参看:Fecshop 配置结构

在上面可以看到,把register部分的功能 enable设置成false,进而关掉了注册账号发送邮件,

对于其他地方的发送邮件,都可以通过这种方式进行关闭邮件的发送。

如果要开启邮件发送,必须配置smtp

xiaobeibei#23年前 0 个赞

报的是这个错误,好像不是配置的问题哦

Fecmall#33年前 0 个赞

@xiaobeibei [[#2楼](#comment2)](#comment2) 把报错完整复制出来

你提问的时候就应该完整复制出来,问问题,问题都不描述清楚,浪费时间吗?

有报错信息,信息都不复制出来,贴上来,让别人给你解决,你自己想一下你的逻辑是不是有问题,别人回答你的问题,也这样描述不清楚,你什么感觉?

xiaobeibei#43年前 0 个赞

嗯 我的问题,以后绝不会这样了

Fecmall#53年前 0 个赞

@xiaobeibei #4楼 把log日志贴出来,截图看不完整,还不知道自己的问题吗?

6楼 已删除.
xiaobeibei#73年前 0 个赞
An Error occurred while handling another error:
exception 'ReflectionException' with message 'Method fecshop\services\Email::send() does not exist' in /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php:195
Stack trace:
#0 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(195): ReflectionMethod->__construct('fecshop\\service...', 'send')
#1 /home/cuiky/fecshop/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php(26): yii\web\ErrorHandler->addTypeLinks('fecshop\\service...')
#2 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/View.php(330): require('/home/cuiky/fec...')
#3 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/View.php(250): yii\base\View->renderPhpFile('/home/cuiky/fec...', Array)
#4 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(249): yii\base\View->renderFile('@yii/views/erro...', Array, Object(yii\web\ErrorHandler))
#5 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(304): yii\web\ErrorHandler->renderFile('@yii/views/erro...', Array)
#6 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(326): yii\web\ErrorHandler->renderCallStackItem('/home/cuiky/fec...', 53, 'fecshop\\service...', 'send', Array, 12)
#7 /home/cuiky/fecshop/vendor/yiisoft/yii2/views/errorHandler/exception.php(381): yii\web\ErrorHandler->renderCallStack(Object(Swift_TransportException))
#8 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/View.php(330): require('/home/cuiky/fec...')
#9 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/View.php(250): yii\base\View->renderPhpFile('/home/cuiky/fec...', Array)
#10 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(249): yii\base\View->renderFile('@yii/views/erro...', Array, Object(yii\web\ErrorHandler))
#11 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(116): yii\web\ErrorHandler->renderFile('@yii/views/erro...', Array)
#12 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(Swift_TransportException))
#13 [internal function]: yii\base\ErrorHandler->handleException(Object(Swift_TransportException))
#14 {main}
Previous exception:
exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.qq.com [php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution #0]' in /home/cuiky/fecshop/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:268
Stack trace:
#0 /home/cuiky/fecshop/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection()
#1 /home/cuiky/fecshop/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)
#2 /home/cuiky/fecshop/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#3 /home/cuiky/fecshop/vendor/yiisoft/yii2-swiftmailer/Mailer.php(145): Swift_Mailer->send(Object(Swift_Message))
#4 /home/cuiky/fecshop/vendor/yiisoft/yii2/mail/BaseMailer.php(262): yii\swiftmailer\Mailer->sendMessage(Object(yii\swiftmailer\Message))
#5 /home/cuiky/fecshop/vendor/yiisoft/yii2/mail/BaseMessage.php(48): yii\mail\BaseMailer->send(Object(yii\swiftmailer\Message))
#6 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/services/Email.php(227): yii\mail\BaseMessage->send()
#7 [internal function]: fecshop\services\Email->actionSend(Array, 'default')
#8 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/services/Service.php(48): call_user_func_array(Array, Array)
#9 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/services/email/Customer.php(53): fecshop\services\Service->__call('send', Array)
#10 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/services/email/Customer.php(53): fecshop\services\Email->send(Array, 'default')
#11 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Customer/block/account/Register.php(74): fecshop\services\email\Customer->sendRegisterEmail(Array)
#12 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Customer/block/account/Register.php(61): fecshop\app\appfront\modules\Customer\block\account\Register->sendRegisterEmail(Array)
#13 /home/cuiky/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Customer/controllers/AccountController.php(81): fecshop\app\appfront\modules\Customer\block\account\Register->register(Array)
#14 [internal function]: fecshop\app\appfront\modules\Customer\controllers\AccountController->actionRegister()
#15 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#17 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('register', Array)
#18 /home/cuiky/fecshop/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('customer/accoun...', Array)
#19 /home/cuiky/fecshop/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(fecshop\yii\web\Request))
#20 /home/cuiky/fecshop/appfront/web/index.php(97): yii\base\Application->run()
#21 {main}

Fecmall#83年前 0 个赞

应该就是smtp导致的报错。参看上面的回答,自己解决吧

先关掉注册页面的邮件发送,看看是否报错,如果不报错,就是smtp的问题

xiaobeibei#93年前 0 个赞

好的

xiaobeibei#103年前 0 个赞

谢谢

Fecmall#113年前 0 个赞

@xiaobeibei #7楼 你的测试环境是win还是linux?php版本等等,说一下你的环境。

xiaobeibei#123年前 0 个赞

linux的,php版本5.4.34,所有的配置都是按照您的文档的版本来弄的

Fecmall#133年前 0 个赞

@xiaobeibei [#12楼](#comment12) 线上是没有问题的:https://fecshop.appfront.fancyecommerce.com/customer/account/register

这个报错不是程序问题,是你的服务器连接smtp.qq.com失败导致的。

我让其他本地安装fecshop的测试了下,他们是正常的,是不是你的网络问题,或者其他,你自己排查看看吧。

1.你在smtp的配置中换一个smtp配置,试试,是否可以。

2.或者先关掉register的邮件发送,可能换个服务器就好了

xiaobeibei#143年前 0 个赞

嗯 好的,谢谢 Terry

Fecmall#153年前 0 个赞

@xiaobeibei #14楼

应该是你的本地网络有问题,无法连接smtp.qq.com

water#163年前 0 个赞

如果找到原因,或者其他,这里回复下结果。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics