【问题标题】:Where the mail is addressed within Symfony2?Symfony2 中的邮件地址在哪里?
【发布时间】: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


【解决方案1】:

选项 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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 2019-01-07
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多