/**
* 发邮件
*
* @param array $receiver 接收人信息
* @param array $attachment_info 附件信息
* @param string $is_html 是否html内容 默认值不是
* @param string $mail_title 邮件标题
* @param string $mail_body 邮件内容
* @return boolean 发送成功与否
*
*
* ===================
* $receiver = array(
* array('mail_address'=>'xxx@qq.com','user_name'=>'张三','type' => 1),
* array('mail_address'=>'xxx@qq.com','user_name'=>'李四','type' => 2),
* array('mail_address'=>'xxx@qq.com','user_name'=>'张三','type' => 3),
* )
* type: 1-密送 2-抄送 3-主送
* ===================
*
* ===================
* $attachment_info = array(
* array('file_full_name' => 'xx/xxx/test.jpg', 'attachment_name'=> 'beautiful.jpg'),
* array('file_full_name' => 'xx/xxx/test.jpg', 'attachment_name'=> 'beautiful.jpg'),
*
* )
* file_full_name 文件全路径 attachment_name 邮件里边的附件名称
* ===================
*/
function sendMail($receiver, $mail_title = "sysinfo", $mail_body = 'test', $attachment_info = array(), $is_html = false){
if (empty($receiver)){
return false;
}
require_once LIB_PATH . '/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->CharSet='UTF-8'; // 设置邮件的字符编码,这很重要,不然中文乱码
$mail->Host = 'smtp.exmail.qq.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // 开启认证
$mail->WordWrap = 50; //设置每行最大字符数,超过改数后自动换行
$mail->Username = 'aaa@xxx.com'; // SMTP username
$mail->Password = 'bbb@xxx'; // SMTP password /*设置信件是否是HTML格式*/
$mail->isHTML($is_html); /*发件人信息*/
$mail->From = 'aaa@xxx.com';
$mail->FromName = '系统'; /*添加收件人*/
if (!empty($receiver)){
foreach ($receiver as $val){
if (empty($val['mail_address'])){
continue;
}
if ($val['type'] == 1){
$mail->addBCC($val['mail_address'], $val['user_name']); //密送,不出现在收件方列表里边
}elseif($val['type'] == 2){
$mail->addCC($val['mail_address'], $val['user_name']); //抄送
}elseif ($val['type'] == 3){
$mail->addAddress($val['mail_address'], $val['user_name']); //主送
}
}
} /*添加附件*/
if (!empty($attachment_info)){
foreach ($attachment_info as $val){
if (empty($val['file_full_name'])){
continue;
}
$mail->addAttachment($val['file_full_name'], $val['download_name']);
}
} /*标题*/
$mail->Subject = $mail_title;
/*内容*/
$mail->Body = $mail_body; /*发信*/
if(!$mail->send()) {
//$mail->ErrorInfo;
return false;
} else {
return true;
}
}

  

使用 PHPMailer 发邮件的更多相关文章

  1. # PHP - 使用PHPMailer发邮件

    PHPMailer支持多种邮件发送方式,使用起来非常简单 1.下载PHPMailer https://github.com/PHPMailer/PHPMailer,下载完成加压后, 把下边的两个文件复 ...

  2. 利用第三方类 phpmailer 发邮件

    第一.百度一下 phpmailer 随便找个 girhub 网站 download 下来即可. 第二.复制如下代码放在项目根目录,填写完整你的账号信息,即可发送邮件.就是这么简单! <?php ...

  3. 用phpmailer发邮件 中文乱码问题解决

    加入如下代码解决. $mail->CharSet = "GB2312"; //utf-8; $mail->Encoding = "base64"; ...

  4. Thinkphp5的使用phpmailer实现发邮件功能(163邮箱)

    Thinkphp5本身并没有实现发邮件的功能,至少据我所知. 本文利用网易邮箱作为发邮件的邮箱.作为发送邮件的前提是需要开启SMTP服务,打开网易邮件,点击设置按钮,如下图所示 勾选smtp服务 保存 ...

  5. 怎么使用PHPMailer实现邮件的发送??

    来源:http://www.ido321.com/1103.html 发送邮件是常用的功能,LZ今天在项目中也碰到了,特此分享一下. 首先,去下载PHPMailer 1.https://github. ...

  6. ###使用phpmailer自动邮件提醒

    近期的一个小项目中需要用到邮件自动通知功能,搜了搜,发现phpmailer这个东西大家用的挺多的. 首先去sourceforge下载phpmailer,也可去我的网盘下载,我用的是5.1版本的. 看到 ...

  7. phpmailer实现邮件发送

    phpmailer实现邮件发送 1.代码 <?php require("class.phpmailer.php"); //这个是一个smtp的php文档,网上可以下载得到 $ ...

  8. php发邮件:swiftmailer, php邮件库——swiftmailer

    php发邮件:swiftmailer, php邮件库——swiftmailer 最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送 ...

  9. PHP 发邮件《转》

    导读:PHP自带的mail()函数,是php内置发邮件的函数,该函数虽然简单,但是要想真正可以发邮件得有很复杂的配置.不适合新手,以及项目实际的应用的开发. php的mail()函数复杂配置,使得直接 ...

随机推荐

  1. MySQL查询时,查询结果如何按照where in数组排序

    MySQL查询时,查询结果如何按照where in数组排序 在查询中,MySQL默认是order by id asc排序的,但有时候需要按照where in 的数组顺序排序,比如where in的id ...

  2. LeetCode(278)First Bad Version

    题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, t ...

  3. eclipse使用技巧的网站收集——转载(二)

    写代码离不开文本编辑器,看代码也离不开,iar和keil编辑和阅读简直一般般了,因此使用eclipse可以看看代码,提高效率.网上有几个博客的文章,这里收集一下,以备忘. 以下文章转载自:http:/ ...

  4. Three displays CodeForces - 987C (dp)

    C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Gym - 100781G Goblin Garden Guards (扫描线)

    题意: n 只哥布林,每只哥布林都有一个位置坐标. m 个炮台,每个炮台都有一个位置坐标和一个攻击半径. 如果一个哥布林在任何一个炮台的攻击范围内,都会被杀死. 求最后没有被杀死的哥布林的数量. 这题 ...

  6. 制作iso文件

     genisoimage -o fusionstor-yi-2017-03-08.iso(镜像名称) -v -cache-inodes -joliet-long -R -J -T -V ZS  -c  ...

  7. jenkins配置邮箱时出错

    jenkins配置邮箱时出错: 这有可能是此博客http://www.cnblogs.com/yajing-zh/p/5109517.html在配置jenkins发送邮件时的第4步和第5步中的邮箱不匹 ...

  8. 主席树 - Luogu 1001 A+B problem

    看着大佬们的解法我瑟瑟发抖 我用主席树写一写吧 #include<iostream> #include<iomanip> #include<cmath> #incl ...

  9. 国内外移动端web适配屏幕方案总结

    基础知识点 设备像素:设备像素又称物理像素(physical pixel),设备能控制显示的最小单位,我们可以把这些像素看作成显示器上一个个的点. iPhone5的物理像素是640X1136. PS: ...

  10. PTA 11-散列2 Hashing (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/679 5-17 Hashing   (25分) The task of this pro ...