Sha*_*rop 19 swiftmailer symfony
我在使用symfony2和swiftmailer发送电子邮件时遇到问题.我对如何调试此问题也有点迷失.下面是代码.首先,我正在创建一个要显示的表单.在提交(request-> method == post)后,我尝试发送电子邮件.我没有收到任何错误,它将我带到了谢谢你的页面,但是,我没有收到任何电子邮件.我已经测试了prod和dev.在开发中,我在提交后打开了探查器,它显示了0封电子邮件.任何帮助表示赞赏!谢谢!
public function contactAction(Request $request)
{
$defaultData = array('name' => 'Name', 'email' => 'Email', 'subject' => 'Subject', 'message' => 'Message');
$form = $this->createFormBuilder($defaultData)
->add('name', 'text')
->add('email', 'email')
->add('subject', 'text')
->add('message', 'textarea')
->getForm();
if($request->getMethod() == 'POST') {
$form->bindRequest($request);
$data = $form->getData();
$message = \Swift_Message::newInstance()
->setSubject($data['subject'])
->setFrom('no-reply@mysite.com')
->setTo('email@mysite.com')
->setBody($this->renderView('AdaptiveSiteBundle:Default:email.txt.twig', array('name' => $data['name'], 'message' => $data['message'])))
;
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('thankyou'));
}
return array("form" => $form->createView());
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*bad 24
你能发贴参数吗?
还要确保禁用假脱机,以便立即发送电子邮件.如果在Swiftmailer配置下有假脱机条目,请将其删除,例如:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
应该:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
sme*_*tek 13
您可能有邮件假脱机设置.如果是这种情况,您需要运行:
php app/console swiftmailer:spool:send
Run Code Online (Sandbox Code Playgroud)
发送假脱机电子邮件.
有关更多信息,请访问http://symfony.com/doc/master/cookbook/email/spool.html.
Mil*_*loš 10
您可以在这里找到有关如何使用symfony2发送电子邮件的整个过程.我只是测试它似乎工作正常.
http://tutorial.symblog.co.uk/docs/validators-and-forms.html#sending-the-email
http://symfony.com/doc/current/email.html
我经常在config_dev.yml中将以下配置设置为在测试期间发送的--prevent-邮件,也许你已经做了同样的事情而忘记了?
如果这是在config_dev.yml中,请将其设置为false:
swiftmailer:
disable_delivery: true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40833 次 |
| 最近记录: |