邮件在 Symfony2 中的地址在哪里?
Where the mail is addressed within Symfony2?
我正在实施 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 ,而不是主机和传输是否正确。感谢大家!
选项 1
有一篇与您的问题相关的优秀食谱文章
http://symfony.com/doc/current/cookbook/email/dev_environment.html
这篇文章有很多方法可以知道你的邮件是否正在发送(在本地服务器上调试)
选项 2
你可能想看看http://mailcatcher.me/
安装后,您只需将 SMTP 配置指向 mailcatcher 提供的配置,即可查看您的应用发送的所有邮件
选项 3
如您的配置所述,假脱机正在使用内存。
尝试将其更改为基于文件并设置电子邮件在发送前的存储路径(您需要 运行 swiftmailer:spool:send
命令才能真正发送电子邮件)
config.yml
swiftmailer:
default_mailer: default
mailers:
delayed:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
port: %mailer_port%
spool:
type: file
path: "%kernel.root_dir%/spool"
我正在实施 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 ,而不是主机和传输是否正确。感谢大家!
选项 1
有一篇与您的问题相关的优秀食谱文章 http://symfony.com/doc/current/cookbook/email/dev_environment.html
这篇文章有很多方法可以知道你的邮件是否正在发送(在本地服务器上调试)
选项 2
你可能想看看http://mailcatcher.me/ 安装后,您只需将 SMTP 配置指向 mailcatcher 提供的配置,即可查看您的应用发送的所有邮件
选项 3
如您的配置所述,假脱机正在使用内存。
尝试将其更改为基于文件并设置电子邮件在发送前的存储路径(您需要 运行 swiftmailer:spool:send
命令才能真正发送电子邮件)
config.yml
swiftmailer:
default_mailer: default
mailers:
delayed:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
port: %mailer_port%
spool:
type: file
path: "%kernel.root_dir%/spool"