Swiftmailer Symfony已发送3:1电子邮件但未显示任何内容

时间:2018-04-26 08:44:19

标签: swiftmailer

我试图发送一封包含symfony 3,swiftmailer和twig的电子邮件。 我正在使用formbuilder进行表单,当有人点击提交按钮时,它会发送邮件。我没有错误,只有#3; 1假脱机消息"。

我尝试了什么:我做过:php bin/console swiftmailer:email:send 它返回:[确定]已成功发送1封电子邮件。 (也在这里,我没有邮件)。 在我的两个方框中,我对连接的限制较少。

我的代码如下: 对于控制器:

/**
 * @Route("testmail", name="testmail")
 */
public function testmail(Request $request)
{

    $societe = null;
    $form = $this->createFormBuilder()
        ->add('Societe', TextType::class, array('label' => 'Société'), array('constraints' => array(new NotBlank(array()),
            new Length(array('min' => 2,
                'max' => 25)))))
        -> add('send',SubmitType::class, array('label' => 'Cotation'))

        ->getForm();

    $form->handleRequest($request);

    if ($form->isValid()) {
        if ($request->isMethod('POST')) {
            $societe = $form["Societe"]->getData();

            $message = \Swift_Message::newInstance()
                ->setSubject('Etude Financiere')
                ->setFrom('wolffvianney@gmail.com')
                ->setTo('vianney.wolff@yahoo.fr')
                ->setCharset('utf-8')
                ->setContentType('text/html')
                ->setBody($this->render('@gkeep/Finance/email.html.twig', array('Societe' => $societe)));

            $this->get('mailer')->send($message);


        }
    }

    return $this->render('@gkeep/Finance/finance.html.twig', array('form' =>$form->createView(),
    'Societe'=>$societe));


}

config.yml:

swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }

parameters.yml:

mailer_transport: mail
mailer_host: smtp.gmail.com
mailer_user: wolffvianney@gmail.com
mailer_password: *mypasswordforwolffvianney@gmail.com*
secret: thesecret

Finance / email.html.twig

<html>
hi
société : {{ Societe }}
</html>

如果有人有任何建议或帮助,我可以根据需要发送其他文件。我不明白什么是错的,谢谢你提前。 (我也试图删除行spool{type:memory 然后它说已经发送了1封电子邮件,但在这里,我也没有收到任何邮件。

Vianney

1 个答案:

答案 0 :(得分:0)

尝试

php bin/console swiftmailer:spool:send --env={your_env}
相关问题