我试图在坚持之后发送消息。当我使用常规方式时,它可以正常工作
addReservatieAction:
public function addReservatieAction(Request $request, \Swift_Mailer $mailer)
{ //the rest of the code is also here
$message = (new \Swift_Message('Hello Email'))
->setFrom('example@live.nl')
->setTo($email)
->setBody("$success,<br>Email:$email,<br>Name:$name,<br>
StartDate:$start_date,<br>EndDate:$end_date", 'text/html');
$mailer->send($message);
}
但我想为这样的邮件制作另一个功能:
addReservatieAction:
public function addReservatieAction(Request $request, \Swift_Mailer $mailer)
{
$reservatie = new reservatie();
$form = $this->createForm(reservatieType::class, $reservatie);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$message=$this->sendEmail();
//add flashbag is room is booked
$mailer->send($message);
$url = $this->generateUrl('index_reservatie');
return $this->redirect($url);
}
public function sendEmail (){
$reservatie = new reservatie();
$start_date = $reservatie->getDateIn();
$start_date = $start_date->format('d-m-y');
$end_date = $reservatie->getDateOut();
$end_date = $end_date->format('d-m-y');
$message = (new \Swift_Message('Hello Email'))
->setFrom('example@live.nl')
->setTo($email)
->setBody(" StartDate:$start_date,<br>EndDate:$end_date", 'text/html');
return $message;
}
但问题是它一直给我这个错误:
在null
上调用成员函数format()
我在约会时使用它并非空。