yangakw yangakw

php用redis做消息队列发送邮件

in 代码read (137) 文章转载请注明来源!

<?php

/**
 * Created by PhpStorm.
 * User: lyang
 * Date: 2016/10/20
 * Time: 10:32
 */
namespace UT\Common\Lib\Email;

use UT\Common\Lib\Crypt;

class Email
{
    const AltBody             = "为了查看该邮件,请切换到支持 HTML 的邮件客户端"; 
    public $EMAILER;
    /**
     * @param \PHPMailer $mail
     * @param            $to
     * @param            $subject
     * @param string     $body
     *
     * @return bool|int
     */
    public function postmail(\PHPMailer $mail, $to, $subject, $body = '')
    {
        $mail->Subject = $subject;
        $mail->AltBody = self::AltBody;
        $mail->msgHTML($body);
        $mail->addAddress($to,$to);
        if (!$mail->send()) { 
            return false;
        } else { 
            return true;
        }
    } 
    /**
     * @return \PHPMailer
     */
    public static function getMailer()
    {
        if(self::$EMAILER instanceof \PHPMailer){
            return self::$EMAILER;
        }
        $mail = new \PHPMailer();
        $mail->isSMTP();
        $mail->SMTPDebug   = self::EMAIL_DEBUG;
        $mail->Debugoutput = 'html';
        $mail->Host        = "smtp.163.com";
        $mail->Port        = 25;
        $mail->SMTPAuth    = true;
        $mail->CharSet     = "utf-8";
        $mail->Username    = "yangakw@163.com";
        $mail->Password    = "*******";
        $mail->setFrom('yangakw@163.com', 'yangakw@163.com'); 
        return self::$EMAILER = $mail;
    }

    /**
     * @return \Redis
     */
    public static function getRedis()
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        return $redis;
    }
    /**
     * @param $email
     * @param $subject
     * @param $body
     *
     * @return int
     */
    public static function pushEmailQueue($email, $subject, $body)
    {
        $redis           = self::getRedis();
        $data["email"]   = $email;
        $data["subject"] = $subject;
        $data["body"]    = $body;
        return $redis->lpush("EMAIL", json_encode($data));
    }  
}

jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

发表新评论
仅有 1 条评论
  1. Gueststemy
    Gueststemy
    回复

    guest test post
    bbcode
    html
    http://googlee.te/ simple

博客已运行
© 2017 yangakw
PREVIOUS NEXT
雷姆
拉姆