【发布时间】:2015-07-21 02:39:01
【问题描述】:
我正在实现 SwiftmailerBundle,一切似乎都运行良好,但如果邮件已发送,则情况并非如此。我想问一下邮件在 Symfony2 中的存储位置。我显示我的代码:
config.yml
# Swiftmailer Configuration
swiftmailer:
transport: smtp
host: smtp.live.com
username: mymail@hotmail.com #my account
password: ******** #my password
spool: { type: memory }
TablasController.php
public function registroAction()
{
$peticion = $this->getRequest();
$em = $this->getDoctrine()->getManager();
$user = new User(); //creo el usuario
$datos = new Datos();
$user->setDatos($datos);
$crearusuario = true;
$formulario = $this->createForm(new RegistroUsuarioType(), $user);
if ($peticion->getMethod() == 'POST')
{
$formulario->submit($peticion);
$newuser = $this->get('request')->request->get('username'); //recupero el usuario ingresado
$em = $this->getDoctrine()->getManager();
$todos = $em->getRepository('AtajoBundle:User')->findByUsuario();
foreach($todos as $todo)
{
if($todo == $newuser)
{
$crearusuario = false;
}
}
if ($formulario->isValid() and $crearusuario != false) {
$encoder = $this->get('security.encoder_factory')->getEncoder($user);
$user->setSalt(md5(time()));
$passwordCodificado = $encoder->encodePassword($user->getPassword(), $user->getSalt() );
$user->setPassword($passwordCodificado);
$em = $this->getDoctrine()->getManager();
//si todo es correcto, busco el rol 'ROLE_USER' de la tabla ROLE..
//y lo relaciono con el usuario.
$role = $em->getRepository('ProyectoSeguridadBundle:Role')->findByRole('ROLE_USER'); //busco el rol
$user->setRoles($role); //los relaciono
$em->persist($user); //persisto el usuario
$em->flush();
$mail = $this->get('request')->request->get('email');
$empresa = $this->get('request')->request->get('empresa');
$cuit = $this->get('request')->request->get('cuit');
$localidad = $this->get('request')->request->get('localidad');
$calle = $this->get('request')->request->get('calle');
$altura = $this->get('request')->request->get('altura');
$telefono = $this->get('request')->request->get('telefono');
$celular = $this->get('request')->request->get('celular');
$message = \Swift_Message::newInstance()
->setSubject('Bienvenido a LM Lavoc')
->setFrom('mymail@hotmail.com')
->setTo($mail)
->setBody(
$this->renderView(
'AtajoBundle:Mails:bienvenido.html.twig',
array('name' => $newuser, 'mail' => $mail, 'empresa' => $empresa, 'cuit' => $localidad,
'calle' => $calle, 'altura' => $altura, 'telefono' => $telefono, 'celular' => $celular)
));
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('home'));
}
}
这是记录用户的功能,一切正常,更重要的是,信息存储在数据库中。问题不在于是否发送了邮件,而且无论如何,正如我所见。我还想验证 config.yml 中的设置是否正确,我使用 hotmail ,而不是主机和传输是否正确。谢谢大家!
【问题讨论】:
-
从问题中看不出你的问题是什么。
-
邮件在 symfony 中的保存位置,提交时间?
-
它们完全按照您指定的方式存储在内存线轴中。它的类名是
Swift_MemorySpool -
我怎样才能看到它们?文件的路径是什么?
-
您看不到它们,它们仅在请求处理期间存储在内存中。 “文件的路径是什么”---你为什么不尝试搜索?
标签: php email symfony config swiftmailer