phpmailer{群发并且发送附件}
PHPMailer是一个用于发送电子邮件的PHP函数包。
第一,需要下载PHPMailer文件包phpmailer. http://phpmailer.sourceforge.net/
第二,确认你的服务器系统已经支持socket ,通过phpinfo();查看是否支持sockets(socket 是属于PHP扩展部分),如果显现为 “enabled”,那就是支持了。
第三,把文件解压到你的web服务器目录下,调用类就可以了.
首先包含class.phpmailer.php,然后创建对象,设置参数,调用成员函数。具体请见下面的示例代码:
require("phpmailer/class.phpmailer.php");
function smtp_mail ($send,$sendto,$sendto_email, $subject, $body) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = $send['Host']; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $send['Username']; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = $send['Password']; // SMTP password
$mail->From = $send['From']; // 发件人邮箱
$mail->FromName = $send['FromName']; // 发件人
if(!empty($sendto['AddCC'][0])){ // 添加抄送
for($i=0;$i<count($sendto['AddCC']);$i++)
{
$mail->AddCC($sendto['AddCC'][$i]);
}
}
if(!empty($sendto['AddBCC'][0])){ // 添加密送
for($i=0;$i<count($sendto['AddBCC']);$i++)
{
$mail->AddBCC($sendto['AddBCC'][$i]);
}
}
$mail->CharSet = "UTF-8"; // 这里指定字符集
$mail->Encoding = "base64";
$mail->MessageID = time();
for($i=0;$i<count($sendto['sendto_email']);$i++)
{
$mail->AddAddress($sendto['sendto_email'][$i]); // 收件人邮箱地址
}
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject; // 邮件主题
// 邮件内容
$mail->Body = '<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body> '.
$sendto['body']
.'</body>
</html> ';
if(!empty($sendto['AddAttachment'][0])){
foreach($sendto['AddAttachment'] as $value){
$mail->AddAttachment('D:/wwwSer/www/nwebs/uploads/'.$value); // 附件的路径和附件名称
}
}
$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "发送有误 <p>";
echo "错误信息: " . $mail->ErrorInfo;
exit;
}
else{
echo "发送成功!<br/>";
}
}
$send = array( // 接收所需要的数据
'Host' =>$Data2['info'][0]->SMTP,
'Username' =>$Data2['info'][0]->username,
'Password' =>$Auth->Auth_EmailPwDecrypt($Data2['info'][0]->password),
'From' =>$COMMON->Post("senduser"),
'FromName' =>$userinfo->username
);
$sendto = array(
'sendto_email' => $SendTo3,
'AddCC' => $AddCC3,
'AddBCC' => $AddBCC3,
'subject' => $COMMON->Post("subject"),
'body' => $COMMON->Post("content"),
'AddAttachment'=> $FilesNames2
);
//(发送到, 邮件主题, 邮件内容,用户名)
smtp_mail($send, $sendto, $sendto['sendto_email'], $sendto['subject'], $sendto['body']);
}
要注意的内容:
如果你想用它来群发邮件的话,记得修改包含文件函数,如: require("phpmailer/class.phpmailer.php");
改为 require_once("phpmailer/class.phpmailer.php"); 否则的话会产生类的重定义。
phpmailer{群发并且发送附件}的更多相关文章
- TP5使用phpmailer实现邮件发送
1.从github下载PHPMailer,在vendor目录中新建文件夹phpmailer,将压缩包中的class.phpmailer.php和class.smtp.php复制到phpmailer中, ...
- 【Thinkphp 5】 整合邮箱类 phpmailer实现邮件发送
第一步:下载phpmailer文件,主要用到的文件只有箭头指向的两个,thinkphp5中,把class.phpmailer.php改成了phpmailer.php 第二步: 将phpmailer文件 ...
- phpmailer实现邮件发送
phpmailer实现邮件发送 1.代码 <?php require("class.phpmailer.php"); //这个是一个smtp的php文档,网上可以下载得到 $ ...
- python 发送附件至邮箱
python 发送附件至邮箱 import smtplibfrom email.MIMEText import MIMETextfrom email.MIMEMultipart import MIME ...
- Flask-email 发送邮件的配置,发送附件的方法,以及os.environ.get('MAIL_USERNAME')为None的解决办法
一.发送邮件的配置 在学习flask-mail来发送电子邮件的时候遇到了一些问题,其实都是些小问题,现在记录下来以便于以后查看. 1.首先flask-mail的安装 pip install flask ...
- python测试开发django-30.发送附件EmailMessage
前言 Django的 send_mail() 和 send_mass_mail() 函式事实上是对 EmailMessage 类使用方式 的一个轻度封装.send_mail() 和相关的其他封装函式并 ...
- Mac怎么快速创建便签和发送附件的邮件
1.如何快速创建便签 在Mac的任意界面选中文字:shift+command+y 就能创建便签2.如何快速发送附件的邮件(网页界面) 在Safari网页界面 command ...
- hMailServer之发送附件大小限制
hMailServer发送附件大小限制有以下几个地方: 1.php配置 参考 .post_max_size = 10M 表单提交最大数据为10M.此项不是限制上传单个文件的大小,而是针对整个表单的提交 ...
- gomail发送附件
采用github.com/go-gomail/gomail/ 的邮件功能,可以发送附件 以及html文档,下面是其给出的demo,测试通过. package main //cmd: go get go ...
随机推荐
- 交叉编译中的 --sysroot 等等在编译时的作用
--sysroot=dir 的作用 如果在编译时指定了-sysroot=dir 就是为编译时指定了逻辑目录.编译过程中需要引用的库,头文件,如果要到/usr/include目录下去找的情况下,则会在前 ...
- 5 approach to load UIView from Xib
After the past few years I found that the only manageable way for creating/maintaining view (or any ...
- How to effectively work with multiple files in Vim?
Why not use tabs (introduced in Vim 7)? You can switch between tabs with :tabn and :tabp, With :tabe ...
- Linux下多任务间通信和同步-信号
Linux下多任务间通信和同步-信号 嵌入式开发交流群280352802,欢迎加入! 1.概述 信号是在软件层次上对中断机制的一种模拟,是一种异步通信方式.信号可以直接进行用户空间进程和内核进程之间的 ...
- EL表达式及其定义和使用 转
作者:http://blog.csdn.net/goskalrie/article/details/51315397 简介 EL(Expression Language)表达式语言实在JSP2.0版本 ...
- Linq中Take、TakeWhile、Skip、SkipWhile的比较(转)
参考文章:http://blog.csdn.net/lxfzgg/article/details/20534281 Take() , , , , , , , , , }; ); //从第一个元素开始, ...
- ios 记录支付宝集成遇到的坑及解决方法
今天项目中要开始动手集成支付宝支付,在此小结一下.(目前新版的支付宝SDK有较大改版,去集成还需要自己去开发平台详细的按照集成步骤来完成https://doc.open.alipay.com/docs ...
- 程序猿的编程神器 - vim
一.官方文档: 当你首次安装好 Vim 之后.能够用 :help tutor 或者 :help tutor@cn 命令.进入一个30分钟的 Vim 新手教程.你也能够下载一个 Vim Document ...
- 探索WebKit内核(一)------ 菜鸟起步
为什么搞WebKit 如今研究WebKit的人越来越多,俺不能免俗,也增加当中.WebKit的火爆也是得益于浏览器和WebOS的混战,随着Palm WebOS, Chrome OS, Firefox ...
- STM32的优先级NVIC_PriorityGroupConfig的理解及其使用
写作原由:因为之前有对stm32 优先级做过研究,但是没时间把整理的东西发表,最近项目需要2个串口,但是不是两个串口同时使用,只是随机使用其中一个,程序对2个串口的优先级需要配置: 此文思路:“中断优 ...