Symfony 6使用SMTP的郵件傳送器DSN無法傳送郵件
P粉957661544
P粉957661544 2024-02-17 11:47:47
0
1
282

我正在嘗試使用不同的 SMTP 伺服器使用 Symfony 6 Mailer,但它們都不起作用。

訊息已排隊但未發送。我嘗試從不同的伺服器上排除防火牆或連接埠問題。

沒有日誌訊息或異常,所以我很迷茫。

這是我嘗試過的一些 DSN:

MAILER_DSN="smtp://email%40example.com:[email protected]:587?encryption=tls"
MAILER_DSN="smtp://[email protected]:[email protected]:587?encryption=tls"
MAILER_DSN="smtp://[email protected]:[email protected]:587"

我實際上嘗試了許多帶有/沒有加密的 DSN 組合。我懷疑問題出在 DSN 字串中,因為如果我嘗試錯誤的主機或密碼,效果是相同的。

這是一個長期存在的問題,我很長時間都無法解決。

這是發送程式碼:

use Symfony\Component\Mime\Email;

$email = (new Email())
        ->from($this->parameterBag->get('app.message.email_from'))
        ->to($to)
        ->subject($subject)
        ->text($text)
        ->html($text);

$sentMessage = $this->mailer->send($email);

mailer.yaml內容:

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

以及messenger.yaml內容:

framework:
    messenger:
        failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    use_notify: true
                    check_delayed_interval: 60000
                retry_strategy:
                    max_retries: 3
                    multiplier: 2
            failed: 'doctrine://default?queue_name=failed'
            # sync: 'sync://'

        routing:
            Symfony\Component\Mailer\Messenger\SendEmailMessage: async
            Symfony\Component\Notifier\Message\ChatMessage: async
            Symfony\Component\Notifier\Message\SmsMessage: async

            # Route your messages to the transports
            # 'App\Message\YourMessage': async

P粉957661544
P粉957661544

全部回覆(1)
P粉482108310

根據您目前的信差配置,不會直接傳送電子郵件,而是僅在呼叫 messenger:consume 時傳送。

這是因為 Messenger 正在對電子郵件(或簡訊等其他訊息)進行排隊,而不是立即發送。

您可以在此處了解有關訊息元件的更多資訊 a>,但如果您想暫時忽略它,只需透過修改傳輸配置來同步發送電子郵件。

framework:
    messenger:
        transports:
            async: 'sync://'
        routing:
            Symfony\Component\Mailer\Messenger\SendEmailMessage: async
            Symfony\Component\Notifier\Message\ChatMessage: async
            Symfony\Component\Notifier\Message\SmsMessage: async

            # Route your messages to the transports
            # 'App\Message\YourMessage': async
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!