php - Where the mail is addressed within Symfony2?
I am implementing the SwiftmailerBundle and everything seems to work fine, but not really if the mail is sent . I wanted to ask where the mails are stored inside Symfony2 . I show my code:
config.yml
# Swiftmailer Configuration
swiftmailer:
transport: smtp
host: smtp.live.com
username: [email protected] #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('[email protected]')
->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'));
}
}
It is the function where the user is recorded , everything works fine , it's more , the information is stored in the database. The problem is not whether the mail is sent , and in any case , as I can see . I also want to verify if it's okay settings in config.yml , I use hotmail , not if the host and transport are correct. Thanks to all!
Answer
Solution:
Option 1
There's an excellent cookbook article related to your question http://symfony.com/doc/current/cookbook/email/dev_environment.html
That article has many ways to know if your mails are being sent or not ( Debugging on local server )
Option 2
You may want to look at http://mailcatcher.me/ Once you install this, you can just point the SMTP configuration to the one offered by mailcatcher and view all the mails that your app is sending
Option 3
As mentioned in your configuration, the spool is using memory .
Try changing it to a file based and set a path where the emails will be stored before they are delivered ( you need to run
swiftmailer:spool:send
command to really send the emails )config.yml