PHPMailer 命名空间版

浏览:3227 发布日期:2014/09/18 分类:功能实现 关键字: 发送邮件 PHPMailer
对PHPMailer进行了一点小改造,使之能够使用在ThinkPHP 3.2中使用
将PHPMailer.class.php和Smtp.class.php这两个文件放入ThinkPHP/Library/Vendor文件夹下,然后在控制器中调用:use Vendor\PHPMailer;
函数使用:// 发送邮件
    public function sendEmail($content,$email){
        $mail             = new PHPMailer();
        $body = $content;
        $mail->IsSMTP();
        $mail->SMTPAuth   = true;                     // enable SMTP authentication
        $mail->SMTPKeepAlive = true;                  // sets the prefix to the servier
        $mail->CharSet = "utf-8";                      // 解决乱码
        //send from 163 mail
        $mail->Host       = "smtp.163.com";           // sets SMTP server
        $mail->Port       = 25;
        $mail->Username   = "your email@163.com";     // 用户账号
        $mail->Password   = "your password";                 // 用户密码
        $mail->From       = "your emai@163.com";
        $mail->FromName   = "管理员";
        $mail->Subject    = "密码重置邮件(请勿回复)";
        $mail->AltBody    = $body;
        $mail->WordWrap   = 50;                       // set word wrap
        $mail->MsgHTML($body);
        $mail->AddReplyTo("your email@163.com","admin");
        // $mail->AddAttachment("attachment.jpg");             // 附件1
        // $mail->AddAttachment("attachment.zip");             // 附件2
        $mail->AddAddress($email,"accept");     //接收邮件的账号
        $mail->IsHTML(true); // send as HTML
        return $mail->Send();
    }
关于通过邮件找回密码的逻辑我就不写了,可移步我的博客http://blue7wings.com/2014/09/18/find-back-you-password-through-email/

附件 PHPMailer.tar.gz ( 22.84 KB 下载:287 次 )

评论( 相关
后面还有条评论,点击查看>>