如何从symfony2的表单发送电子邮件?
app/config/config_dev.yml:
swiftmailer:
delivery_address: dev@example.com
控制器:
public function aboutAction($name) {
$message = 'Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('x@gmail.com')
->setTo('x@gmail.com')
->setBody($this->renderView('AgLogBundle:Mail:email.txt.twig', array('name' => $name)));
$this->get('mailer')->send($message);
return $this->render('AgLogBundle::ajouter.html.twig');
}
错误:
Swift_TransportException: Connection could not be established with主机127.0.0.1 [auune连接在一个表中]"明确拒绝"。# 10061)
本地主机上没有安装邮件服务器。您可以尝试使用以下配置通过Gmail发送电子邮件:
# app/config/parameters.yml
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: your_gmail_username
mailer_password: your_gmail_password
http://symfony.com/doc/current/cookbook/email/gmail.html