public function contactAction(Request $request)
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$em = $this->getDoctrine()->getManager();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$name = $form['name']->getData();
$email = $form['email']->getData();
$subject = $form['subject']->getData();
$message = $form['message']->getData();
$contact->setName($name);
$contact->setEmail($email);
$contact->setSubject($subject);
$contact->setMessage($message);
}
$message = \Swift_Message::newInstance()
->setSubject($subject) // here the error
->setFrom('jardisindustrie@gmail.com')
->setTo($email)
->setBody($this->renderView('sendmail.html.twig', array(
'name' => $name,
'message' => $message,
'email' => $email,
'subject' => $subject)), 'text/html');
$this->get('mailer')->send($message);
return $this->render('SDCoreBundle::contact.html.twig', [
'form' => $form->createView()
]);
}
我不知道为什么但它确实运作良好,今天下午我再试一次,我有错误信息......
我想与swiftmailer建立联系表格,通常我喜欢这样,但在这里我不知道为什么会有麻烦。
感谢您的帮助
答案 0 :(得分:0)
您缺少完整的错误消息。但是从第一眼看,创建和发送消息的代码应该在if($form->isSubmitted() && $form->isValid())
块内,否则当表单未被提交但仅显示时,它将尝试发送消息。