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

@admin  December 15, 2016

<?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));
    }  
}

添加新评论

  1. viagra 10 mg effectiveness you cannot post new topics in this forum - viagra 1 dollar 93 cents [...]

    Reply
  2. cialis dosage when to take statistics - cialis 5mg canada total posts - cialis for women review[...]

    Reply
  3. cialis doses - cialis 20 mg cost who is online - buy cialis online site

    Reply
  4. does cialis work - cialis commercials settings - cialis 20 mg 4 tablet knowledge base

    Reply
  5. liquid levitra buy light.cgi - discount generic levitra - levitra 20mg side effects registered users

    Reply
  6. cialis for daily use commercial what - ed clinics - how much the official price of cialis in usa

    Reply
  7. khoso@cialis.com - female cialis usage - buy cialis safley

    Reply
  8. student debt consolidation loans - thda great home loans - do you take food at closing home loa[...]

    Reply
  9. viagra to buy were - no prescription india generic viagra - buy online female viagra for iran

    Reply
  10. viagra nightmares - viagra and alcohol use users browsing this forum - cheap generic viagra usa[...]

    Reply
  11. treatments for ed - viagra dose size you may not post replies - viagra online pharmacy india canada

    Reply
  12. viagra vs super active - viagra 20mg canada msn messenger - viagra you cannot reply to topics i[...]

    Reply
  13. lily icos cialis - cialis cost with insurance display options - cialis generic name pictures

    Reply