我在Symfony2中使用Swiftmailer发送邮件时遇到问题。让我解释一下:当我使用app_dev.php访问我的网站时,我可以发送消息,没有问题(还有,当我在app.php中编写$kernel = new AppKernel('prod', true);
时)
所以,我不明白为什么这在开发中有效,而在产品中无效。
这是我的配置文件:
parameters.yml:
mailer_transport: smtp
mailer_host: ****.ovh.net
mailer_username: postmaster@mywebsite.com
mailer_password: ****
mailer_port: ****
config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_username%"
password: "%mailer_password%"
port: "%mailer_port%"
spool: { type: memory }
这是php代码,但我认为它没有问题,因为正如我所说,在开发模式下没有问题。
$message = 'Swift_Message::newInstance() -> setSubject('Test')
-> setFrom('postmaster@mywebsite.com')
-> setTo($user -> getMail())
-> setBody('Test');
$this -> get('mailer') -> send($message);
如果你知道问题出在哪里,非常感谢。
如果dev中出现问题,但prod没有,请尝试手动删除prod缓存目录,然后重新安装并转储资产。从文档中查看此检查表。