错误使用symfony2发送电子邮件

时间:2014-06-03 15:07:10

标签: php symfony

如何使用symfony2从表单发送电子邮件?

应用程序/配置/ config_dev.yml:

swiftmailer:
    delivery_address:  dev@example.com

的Controler:

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:无法建立连接   主机127.0.0.1 [Aucuneconnexionn�apu�tre�tabliecordl�ordinateur   ciblel�a表达拒绝。 #10061]

1 个答案:

答案 0 :(得分:2)

您在localhost上没有安装邮件服务器。您可以尝试使用此配置发送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

相关问题