[英]Symfony3 - Email not sent from a Command
我無法從產品中的Symfony3中的命令發送電子郵件。
我的代碼:
$message = \Swift_Message::newInstance()
->setSubject('A subject')
->setFrom('email@site.com')
->setTo('email@site.com')
->setBody('content', 'text/html');
$mailer = $this->getContainer()->get('mailer');
$mailer->send($message);
配置文件
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
port: '%mailer_port%'
encryption: '%mailer_encryption%'
spool: { type: memory }
Parameters.yml
mailer_transport: smtp
mailer_host: myhostfromovh
mailer_encryption: null
mailer_port: 587
mailer_user: myuser
mailer_password: mypassword
我沒有錯誤,但是我的郵箱中沒有收到電子郵件。 :(
而且,當我在命令行中編寫時:
php app/console swiftmailer:email:send
我有 :
[2017-12-22 13:31:12] app.ERROR: Exception occurred while flushing email queue: Connection could not be established with host myhostfromovh [Connection refused #111]
我通過smtp.gmail.com或ns0.ovh.net(使用PORT和USER / PASSWORD)更改了自定義主機myhostfromovh ,無事可做,無法正常工作。 :-(
但是! 當我在Controller中執行相同的代碼時,沒問題,我收到了郵件。 所以我不明白。
幫我 ! \\ o /
您已在swiftmail中啟用了電子郵件隊列,這意味着將在內核事件終止(已將響應發送到客戶端之后)期間將電子郵件排隊並發送。
您應該在var / logs / prod.log上出現控制器錯誤
看來您的主機不允許連接到該host:port。 可能的原因?
安裝mailcatcher https://mailcatcher.me/並嘗試將電子郵件發送到您的本地smtp服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.