symfony邮件

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

  3. 参考地址

  4. 参数配置

    # 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
    
  5. 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;
    }
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""