symfony邮件

  1. 参考地址

  2. 参数配置

     # parameters.yml
     parameters:
         mailer_transport:   smtp
         mailer_host:        smtp.qq.com
         mailer_port:        465
         mailer_user:        xxxx@qq.com
         mailer_password:    xxxxxxxxxxx
    
     # config.yml
     swiftmailer:
         transport:            '%mailer_transport%'
         username:             '%mailer_user%'
         password:             '%mailer_password%'
         host:                 '%mailer_host%'
         port:                 '%mailer_port%'
         sender_address:       '%mailer_user%'
         logging:              '%kernel.debug%'
         encryption:           ssl
         spool:
             type:                 memory
         antiflood:
             threshold:            99
             sleep:                0
    
  3. PHP代码

     /**
      * 生成用户邮箱验证码
      * @Route("/verify_email")
      */
     public function verifyEmail()
     {
         $request = Request::createFromGlobals();
         $user_email = $request->query->get('user_email');
         unset($request);
    
         $result = 1231231;
         $message = \Swift_Message::newInstance()
             ->setFrom([$this->getParameter('mailer_user') => '邮箱验证'])
             ->setTo([$user_email => "尊敬的用户"])
             ->setContentType("text/html")
             ->setCharset("UTF-8")
             ->setBody("您好,您的邮箱绑定验证码为:{$result}");
         $this->get('mailer')->send($message);
         $result = [
             'code' => 200,
             'data' => [],
             'msg' => '发送成功'
         ];
    
         $response = new Response();
         $response->headers->set('Content-Type', 'application/json;charset=utf-8');
         $response->setContent(json_encode($result, JSON_UNESCAPED_UNICODE));
         return $response;
     }
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-07-08 16:49:59

results matching ""

    No results matching ""