簡體   English   中英

Symfony swiftmail不會從代碼發送

[英]Symfony swiftmail won't send from code

一段時間以來一直在使用swiftmail掙扎。 我有一個linux服務器,並且sendmail正常工作。 從命令行發送郵件的工作原理。 並且通過命令行使用swiftmail發送也可以,因此配置必須確定。 但是從代碼來看,事實並非如此。 一定已經閱讀了所有這些問題,而我完全感到困惑。

令牌創建成功,一切似乎正常。 日志中沒有錯誤。 但是郵件只是沒有來。 我也嘗試發送到其他域。 就像我說的,它可以從命令行使用如下的mail和swiftmail命令:

bin/console swiftmailer:email:send --subject="Test" --body="test" --from="info@domain.com" --to="test@anotherdomain.com"

這是當前代碼:

$mailer = $this->get('mailer');
$message = $mailer->createMessage()
    ->setSubject('You forgot password')
    ->setFrom('info@domain.com')
    ->setTo($username)
    ->setBody('You forgot your password. Go and change it from http://url.com/change-password/'.$user->getConfirmationToken());

    $mailer->send($message);

這是config.yml:

swiftmailer:
transport:  sendmail
host:       /usr/sbin/sendmail -bs

我遇到了同樣的問題,並通過在Swift Mailer上禁用后台打印來解決了該問題。

您未指定要使用的Symfony版本。 如果您使用的是Symfony 4,則/config/packages/swiftmailer.yaml中應該有一個配置文件。

這是我的:

swiftmailer:
url: '%env(MAILER_URL)%'
#spool:
    #type: 'memory'
    #type: file
    #path: '%kernel.project_dir%/var/spool'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM