【问题标题】:Send user and admin confirmation email发送用户和管理员确认电子邮件
【发布时间】:2017-10-22 10:24:41
【问题描述】:

我创建了一个在发送表单时发送电子邮件的服务。我收到评价很高的管理员,但我想通过电子邮件将其发送给完成表单的用户,前提是电子邮件字段已填写。这是我的服务和我的控制器:

我的服务

public function sendMailInscriptionMjml(Invite $invite, $mailTo)
{
    $subject = 'Inscription invité';
    $template = 'AppBundle:Mail:Invite/inscription.html.twig';
    $templateP = 'AppBundle:Mail:Invite/inscription.txt.twig';

    $this->sendMessage($mailTo, $subject, $template, $templateP, array('invite' => $invite));
}

我的控制器:

/**
 * Creates a new invite entity.
 *
 * @Route("/", name="invite_new")
 * @Method({"GET", "POST"})
 */
public function newAction(Request $request)
{
    $invite = new Invite();

    $form = $this->createForm(InviteType::class, $invite);

    if ($request->isMethod('POST')) {
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($invite);
            $em->flush();

            $this->get('app_mailer')->sendMailInscriptionMjml(
                $invite, $this->getParameter('client_mail_to')
            );

            $this->get('session')->getFlashBag()
                ->add('success', 'Votre inscription à été pris en compte.');

            return $this->redirect(
                $this->generateUrl(
                    'homepage'
                )
            );
        }
    }

    return $this->render('@App/invite/new.html.twig', array(
        'invite' => $invite,
        'form' => $form->createView(),
    ));
}

谢谢。

【问题讨论】:

  • 没有得到问题,所以参数client_mail_to是管理员邮件?或者什么
  • 是管理员邮件这个参数。我想向已完成邮件的用户的电子邮件地址发送一封确认电子邮件。谢谢

标签: php symfony email


【解决方案1】:

我找到了方法,这是我控制器中的解决方案。

/**
 * Creates a new invite entity.
 *
 * @Route("/", name="invite_new")
 * @Method({"GET", "POST"})
 */
public function newAction(Request $request)
{
    $invite = new Invite();

    $form = $this->createForm(InviteType::class, $invite);

    if ($request->isMethod('POST')) {
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $mail = $invite->getEmail();
            $em = $this->getDoctrine()->getManager();
            $em->persist($invite);
            $em->flush();

            $this->get('app_mailer')->sendMailInscriptionMjml(
                $invite, $this->getParameter('client_mail_to')
            );


            $this->get('app_mailer')->sendEmailInvite(
                $invite, $mail
            );


            $this->get('session')->getFlashBag()
                ->add('success', 'Votre inscription à été pris en compte.');

            return $this->redirect(
                $this->generateUrl(
                    'homepage'
                )
            );
        }
    }

    return $this->render('@App/invite/new.html.twig', array(
        'invite' => $invite,
        'form' => $form->createView(),
    ));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-27
    • 2012-11-08
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 2011-03-18
    • 1970-01-01
    相关资源
    最近更新 更多