php - Where the mail is addressed within Symfony2?

97

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!

377

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 runswiftmailer:spool:send command to really send the emails )

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"

People are also looking for solutions to the problem: php - Query to Json: Return Each Column Twice with Different Names

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.