swiftmailer不发送电子邮件

时间:2017-01-30 12:58:22

标签: symfony swiftmailer

我想使用symfony发送电子邮件,但swiftmailer不会发送任何电子邮件。我甚至没有得到错误报告或其他任何东西。那是我的代码:

$mail = \Swift_Message::newInstance()
                ->setSubject('Subject')
                ->setTo('test@example.com') #this is replaced by real email of course
                ->setFrom('test@example.com')
                ->setBody('Testbody');

        $this->get('mailer')->send($mail);

这就是配置:

swiftmailer:
default_mailer: mailer
mailers:
    mailer:
        transport: "%mailer_transport%"
        host:      "%mailer_host%"
        username:  "%mailer_user%"
        password:  "%mailer_password%"
        #spool:     { type: memory }

我甚至尝试将主机设置为不存在的地址,但我没有从swiftmailer或symfony收到任何错误。

我试图找到lib的文件,但symfony文件中没有Swift_Message或newInstance,奇怪

2 个答案:

答案 0 :(得分:0)

使用此代码

    $message = \Swift_Message::newInstance()
            ->setSubject('Validation de votre commande')
            ->setFrom('test@example.com') 
            ->setTo('test@example.com')
            ->setBody('Testbody');
            ->setCharset('utf-8')
            ->setContentType('text/html')
            ->setBody('test');

    $this->get('mailer')->send($message);
app / config / parametres.yml中的

mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: your mail
mailer_password: your password mail
app / config / config.yml中的

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

答案 1 :(得分:0)

我见过有同样问题的人。对他而言,问题在于假脱机队列。它通过明确禁用假脱机来解决:

spool:
      enabled:false

或在代码中刷新队列:

$this->get('mailer')->send($mail);
$spool = $this->get('mailer')->getTransport()->getSpool(); 
$spool->flushQueue($this->get('mailer')->getTransport());

希望它有效!

相关问题