将PHPMailer.class.php 和 Smtp.class.php放在ThinkPHPLibraryVendor下
引用 PHPmailer文件
function send_mail_local($to = '', $subject = '', $body = '', $name = '', $attachment = null)
{
$from_email =C('MAIL_SMTP_USER');//"415569142@qq.com";
$from_name = "达人德州扑克官网";
$reply_email = '';
$reply_name = '';
echo C('MAIL_SMTP_USER');
//require_once('./ThinkPHP/Library/Vendor/PHPMailer/phpmailer.class.php');增加命名空间,可以注释掉此行
$mail = new PHPMailer(); //实例化PHPMailer
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 1; // 关闭SMTP调试功能
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->SMTPSecure = ''; // 使用安全协议
$mail->Host =C('MAIL_SMTP_HOST');//"smtp.163.com"; // SMTP 服务器
$mail->Port = C('MAIL_SMTP_PORT');//25; // SMTP服务器的端口号
$mail->Username =C('MAIL_SMTP_USER');//"415569142@qq.com" ; // SMTP服务器用户名
$mail->Password = C('MAIL_SMTP_PASS');//"zhengfeng01"; // SMTP服务器密码
$mail->SetFrom($from_email, $from_name);
$replyEmail = $reply_email ? $reply_email : $from_email;
$replyName = $reply_name ? $reply_name : $from_name;
if ($to == '') {
$to = C('MAIL_SMTP_CE'); //邮件地址为空时,默认使用后台默认邮件测试地址
}
if ($name == '') {
$name = "1"; //发送者名称为空时,默认使用网站名称
}
if ($subject == '') {
$subject = "1"; //邮件主题为空时,默认使用网站标题
}
if ($body == '') {
$body = "1"; //邮件内容为空时,默认使用网站描述
}
$mail->AddReplyTo($replyEmail, $replyName);
$mail->Subject = $subject;
$mail->MsgHTML($body); //解析
$mail->AddAddress($to, $name);
if (is_array($attachment)) { // 添加附件
foreach ($attachment as $file) {
is_file($file) && $mail->AddAttachment($file);
}
}
return $mail->Send() ? true : $mail->ErrorInfo; //返回错误信息
}