1

我的 Laravel Forge 生产服务器上有一个非常奇怪的错误。

我的 .env 配置和 mail.php 配置变量:

smtp.mailgun.org
587
<mailgun username>
<mailgun server>

smtp
smtp.mailgun.org
<mailgun username>
<mailgun server>

我只是通过服务器上的“echo”转储了这个,所以服务器肯定将配置和 env 的变量视为 mailgun。但是当我尝试通过 Mail::to 发送电子邮件时,我遇到了这个错误:

[2021-09-25 21:20:29] production.ERROR: Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known at /home/forge/maxion.io/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:261)
[stacktrace]
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}()
#1 /home/forge/maxion.io/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(264): stream_socket_client()
#2 /home/forge/maxion.io/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 /home/forge/maxion.io/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize()
#4 /home/forge/maxion.io/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#5 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(521): Swift_Mailer->send()
#6 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(288): Illuminate\\Mail\\Mailer->sendSwiftMessage()
#7 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(187): Illuminate\\Mail\\Mailer->send()
#8 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\\Mail\\Mailable->Illuminate\\Mail\\{closure}()
#9 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(188): Illuminate\\Mail\\Mailable->withLocale()
#10 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php(65): Illuminate\\Mail\\Mailable->send()
#11 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Mail\\SendQueuedMailable->handle()
#12 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#13 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#14 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#15 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Container\\BoundMethod::call()
#16 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\\Container\\Container->call()
#17 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}()
#18 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#19 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\\Pipeline\\Pipeline->then()
#20 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\\Bus\\Dispatcher->dispatchNow()
#21 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}()
#22 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#23 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\\Pipeline\\Pipeline->then()
#24 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware()
#25 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\\Queue\\CallQueuedHandler->call()
#26 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(428): Illuminate\\Queue\\Jobs\\Job->fire()
#27 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\\Queue\\Worker->process()
#28 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(329): Illuminate\\Queue\\Worker->runJob()
#29 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\\Queue\\Worker->runNextJob()
#30 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\\Queue\\Console\\WorkCommand->runWorker()
#31 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#32 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#33 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#34 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#35 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Container\\BoundMethod::call()
#36 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#37 /home/forge/maxion.io/vendor/symfony/console/Command/Command.php(299): Illuminate\\Console\\Command->execute()
#38 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#39 /home/forge/maxion.io/vendor/symfony/console/Application.php(978): Illuminate\\Console\\Command->run()
#40 /home/forge/maxion.io/vendor/symfony/console/Application.php(295): Symfony\\Component\\Console\\Application->doRunCommand()
#41 /home/forge/maxion.io/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun()
#42 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\\Component\\Console\\Application->run()
#43 /home/forge/maxion.io/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#44 /home/forge/maxion.io/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#45 {main}
"} 

出于某种原因,在错误消息中,我们可以看到“mailhog”变量。我搜索了很多,在我的项目中找不到像 mailhog 这样的东西。Mailgun 无处不在。同样在本地主机上,我在发送电子邮件方面没有任何问题,这是 Namecheap VPS 和 Laravel Forge 控制面板上的唯一问题。我已经写信给 Namecheap 支持,他们看不到任何阻塞发出的请求,因此必须从他们这边打开端口。

此外,这里是 telnet 输出:

Trying 3.93.221.84...
Connected to smtp.mailgun.org.
Escape character is '^]'.
Connection closed by foreign host.

有没有人遇到过类似的问题?我尝试了很多东西,但从未成功。我认为线索是 mailhog 变量,尚不清楚它在服务器上究竟是如何进入 Laravel 邮件函数的,以及为什么这只发生在生产中。我很乐意接受任何猜测,因为我的想法已经用完了)

4

1 回答 1

0

在 Laravel 项目目录中,编辑 config/mail.php 并添加以下内容:

'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]

并运行

php artisan config:cache
于 2021-09-25T11:35:22.677 回答