|
本帖最后由 dogwin 于 2014-6-30 22:50 编辑
最近发现个好用的发邮件类-phpmailer分享给小伙伴们:
CI 建 librarise/Phpmail.php
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);
|
评分
-
查看全部评分
|