標題重寫為:Symfony\Component\Mailer\Exception\TransportException:預期的回應代碼為"250",但收到了空回應
P粉350036783
P粉350036783 2023-11-03 21:58:49
0
1
470

我正在使用 Google Workspace SMTP 中繼服務從我的 Laravel 應用程式發送電子郵件。它已經運作良好一年多了,但我不確定到底是什麼阻止了它的運作。 當我嘗試發送電子郵件時,出現以下錯誤:

>>> IlluminateSupportFacadesMail::to('myemail@gmail.com')->send(new AppMailCourseEnrolmentEmail($user, AppCourse::first()));

// The error
SymfonyComponentMailerExceptionTransportException with message 'Expected response code "250" but got an empty response.'

我懷疑這與我從 Laravel 8 升級到 Laravel 9 有關,但不確定如何修復它。

我的mail.php

#
'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
        ],

我的郵件設定

MAIL_DRIVER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=TLS
MAIL_FROM_NAME="My Name"
MAIL_FROM_ADDRESS=myaddress@workspace.com

我透過 IP 進行身份驗證,因此不需要密碼和使用者名字段

我的 GSuite Gmail 路由設定


注意 在上面的配置中,我嘗試檢查 TLS 並將允許的寄件者更改為“僅我網域中的註冊應用程式使用者”,但問題仍然存在。

我嘗試過來自

的建議
  1. https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail- smtp 中繼資料庫佇列驅動程式

  2. Laravel 9 - Infomaniak:預期回應代碼“250”,但收到代碼“550”,並顯示訊息“550 5.7.1 寄件者不符”

  3. https://stackoverflow.com/a/43283422/11752623

  4. https://www.cubebackup.com/blog/how-to-use-google-smtp-service-to-send-emails-for-free/ 方法 3

所有這些都沒有成功。感謝您協助解決此問題。

P粉350036783
P粉350036783

全部回覆(1)
P粉221046425

找到了解決方法, 我在assertResponseCode方法下造訪了vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php。我回應了顯示以下內容的回覆:

421 4.7.0 Try again later, closing connection. (EHLO) r29-200a50c01d0000xxxxxxxxxxxx87edb.28 - gsmtp

有關該錯誤的更多詳細信息,請參閱 Google 文件

#問題在於 Swift Mailer 使用 127.0.0.1 作為發送 Gmail 未知郵件的網域。

因此,解決方案是在 config/mail.php 檔案中設定我的網域名稱

        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN', 'mydomain.com')//this line here
        ],

更多資訊:

  1. https://insights.rytass.com/gmail-smtp-relay-421-4-7-0-try-again-later- opening-connection-ehlo-cfcdac3cf9c7
  2. https://serverfault .com/questions/929559/postfix-error-421-4-7-0-try-again-later- opening-connection-ehlo
#
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!