【发布时间】:2016-09-02 17:30:23
【问题描述】:
我正在尝试创建一个功能,让每个用户都有机会为另一个用户发送电子邮件。这是 Swiftmailer 的基本控制器:
public function contactAction($id)
{
$enquiry = new Enquiry();
$form = $this->createForm(new EnquiryType(), $enquiry);
$from=$this->container->get('security.context')->getToken()->getUser()->getemail();
$em=$this->getDoctrine()->getManager();
$user=$em->getRepository('PfeUserBundle:User')->findBy(array('id'=>$id));
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bind($request);
if ($form->isValid()) {
$message = \Swift_Message::newInstance()
->setSubject('Intello')
->setFrom($from)
->setTo($user->getemail())
->setBody($this->renderView('PfeUserBundle:Contact:contactEmail.txt.twig', array('enquiry' => $enquiry)));
$this->get('mailer')->send($message);
$this->get('session')->getFlashBag()->add('blogger-notice','Ton message a été envoyé avec succès');
// Redirect - This is important to prevent users re-posting
// the form if they refresh the page
return $this->redirect($this->generateUrl('pfe_intello_contact_mail'));
}
}
我有这个错误 错误:在非对象上调用成员函数 getemail()
【问题讨论】:
-
需要设置smtp协议和密码
-
更新是什么意思?你已经尝试过什么?你读过文档吗?
-
@StephanVierkan 我希望任何用户都可以向另一个用户发送电子邮件,但是使用此功能,所有发送的电子邮件都会到达参数中已配置的电子邮件。 yml
-
您阅读文档了吗? Symfony 有很好的文档:symfony.com/doc/current/cookbook/email/email.html
-
这是一个示例:github.com/dancostinel/symfony-email。请仔细阅读,因为它的格式不正确!
标签: php symfony email swiftmailer