dogwin 发表于 2014-6-30 18:05:42

phpmailer 使用

本帖最后由 dogwin 于 2014-6-30 22:50 编辑

最近发现个好用的发邮件类-phpmailer分享给小伙伴们:


CI 建 librarise/Phpmail.php



<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class CI_Phpmail{
      function__construct(){
               require_once(dirname(__FILE__)."/phpmailer/class.phpmailer.php");
      }
      

      function send_email($to,$from,$subject,$body,$from_name) {
                global $error;
                $mail = new PHPMailer();// create a new object
                $mail->IsSMTP(); // enable SMTP
                $mail->SMTPDebug = 0;// debugging: 1 = errors and messages, 2 = messages only
                $mail->SMTPAuth = true;// authentication enabled
                $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
                $mail->Host = 'smtp.gmail.com';
                $mail->Port = 465;
                $mail->Username = GUSER;
                $mail->Password = GPWD;
                $mail->SetFrom($from, $from_name);
                $mail->FromName = $from_name;
                $mail->Subject = $subject;
                //$mail->Body = $body;
                $mail->CharSet="utf-8";
                $mail->Encoding = "base64";
               
                $mail->AltBody = '';
                $mail->WordWrap   = 80;
                $mail->MsgHTML($body);
                $mail->IsHTML(true);
                $mail->AddAddress($to);
                return $mail->Send();
                /*
                if(!$mail->Send()) {
                        $error = 'Mail error: '.$mail->ErrorInfo;
                        return false;
                } else {
                        $error = 'Message sent!';
                        return true;
                }*/
      }
      function test(){
                echo "hello";
      }
}




解压附件 放到 libraries 里
有问题叫我QQ:930988818

补充
librarise/Phpmail.php
librarise/Phpmailer
在controller 引
$this->load->library('phpmail');
$this->phpmail->send_email($to,$from,$subject,$body,$from_name);

okwindows 发表于 2014-6-30 18:37:26

感谢提供,引用的时候如何操作呢

dogwin 发表于 2014-6-30 22:49:09

okwindows 发表于 2014-6-30 18:37
感谢提供,引用的时候如何操作呢

librarise/Phpmail.php
librarise/Phpmailer
在controller 引
$this->load->library('phpmail');
$this->phpmail->send_email($to,$from,$subject,$body,$from_name);

okwindows 发表于 2014-6-30 23:28:13

感谢,顺利发出!

dogwin 发表于 2014-6-30 23:32:45

okwindows 发表于 2014-6-30 23:28
感谢,顺利发出!

{:soso_e113:}
页: [1]
查看完整版本: phpmailer 使用