1

我想使用 symfony 和 gmail 发送电子邮件。我的意思是发件人和收件人都使用gmail。我将 config.yml 配置如下:

swiftmailer:
    transport: gmail
    encryption: ssl
    auth_mode:  login
    host:      smtp.gmail.com
    username:  username
    password:  pass
    spool:     { type: memory }






 $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('sender@gmail.com')
            ->setTo('destination@gmail.com')
            ->setBody('hello')

这段代码正确吗?

另一个注意事项:当我添加此代码时,它起作用了

$form = $this->get('form.factory')->create(new xxxType(), array('key' => 'var'));

但有了这个它不会

$form = $this->createForm(new xxxType(),$entity);
4

2 回答 2

1

您正在使用spool,它会延迟发送电子邮件,直到您实际通过 app/console 命令发送电子邮件。如之前链接的文档中所述,邮件一直保存在内存中。

为了发送电子邮件,您应该停止使用假脱机,或手动发送它们。

于 2013-04-24T10:01:48.187 回答
0

我看看你刚刚忘记的文档

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

来源:http ://symfony.com/doc/2.0/cookbook/email/email.html

于 2013-04-24T10:01:52.383 回答