php transport,PHPMailer - PHP email transport class
**在服务器安装 sendmail**
~~~
sudo apt-get install sendmail
~~~
**启动 sendmail**
~~~
sudo /etc/init.d/sendmail start
~~~
**修改 php.ini**
~~~
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_from = me@example.com
~~~
**Function sendMail**
~~~
/* 调用PHPMailer发送电邮
* @param String $receiver 收件人
* @param String $sender 发件人
* @param String $sender_name 发件人名称如为空则用发件人地址代替
* @param String $subject 邮件主题
* @param String $content 邮件内容
* @param boolean $ishtml 是否html电邮
* @param Array $attachements 附件
* @return boolean
*/
function sendMail($receiver, $sender, $sender_name, $subject, $content, $ishtml=true, $attachments=array()) {
include_once "class-phpmailer.php";
if(empty($receiver) || empty($sender) || empty($subject) || empty($content)){
return false;
}
$mail = new PHPMailer();
//$mail->IsSMTP(); // 经smtp发送
//$mail->Host = "smtp.gmail.com"; // SMTP 服务器
//$mail->Port = 465; // SMTP 端口
//$mail->SMTPSecure = 'ssl'; // 加密方式
//$mail->SMTPAuth = true; // 打开SMTP认证
//$mail->Username = "username"; // 用户名
//$mail->Password = "password"; // 密码
$mail->IsMail(); // using PHP mail() function 有可能會出現這封郵件可能不是由以下使用者所傳送的提示
$mail->From = $sender; // 发信人
$mail->FromName = $sender_name; // 发信人别名
$mail->AddReplyTo($sender); // 回覆人
$mail->AddAddress($receiver); // 收信人
// 以html方式发送
if($ishtml){
$mail->IsHTML(true);
}
// 发送附件
if($attachments){
if(is_array($attachments)){
$send_attachments = array();
$tmp_attachments = array_slice($attachments,0,1);
if(!is_array(array_pop($tmp_attachments))){
if(isset($attachments['path'])){
array_push($send_attachments, $attachments);
}else{
foreach($attachments as $attachment){
array_push($send_attachments, array('path'=>$attachment));
}
}
}else{
$send_attachments = $attachments;
}
foreach($send_attachments as $attachment){
$attachment['name'] = isset($attachment['name'])? $attachment['name'] : null;
$attachment['encoding'] = isset($attachment['encoding'])? $attachment['encoding'] : 'base64';
$attachment['type'] = isset($attachment['type'])? $attachment['type'] : 'application/octet-stream';
if(isset($attachment['path']) && file_exists($attachment['path'])){
$mail->AddAttachment($attachment['path'],$attachment['name'],$attachment['encoding'],$attachment['type']);
}
}
}elseif(is_string($attachments)){
if(file_exists($attachments)){
$mail->AddAttachment($attachments);
}
}
}
$mail->Subject = $subject;// 邮件标题
$mail->Body = $content;// 邮件內容
return $mail->Send();
}
// DEMO
$receiver = 'receiver@test.com';
$sender = 'sender@test.com';
$sender_name = 'sender name';
$subject = 'subjecct';
$content = 'content';
// 四種格式都可以
$attachments = 'attachment1.jpg';
$attachments = array('path'=>'attachment1.jpg', 'name'=>'附件1.jpg');
$attachments = array('attachment1.jpg','attachment2.jpg','attachment3.jpg');
$attachments = array(
array('path'=>'attachment1.jpg', 'name'=>'附件1.jpg'),
array('path'=>'attachment2.jpg', 'name'=>'附件2.jpg'),
array('path'=>'attachment3.jpg', 'name'=>'附件3.jpg'),
);
$flag = sendMail($receiver, $sender, $sender_name, $subject, $content, true, $attachments);
echo $flag;
?>
~~~
源碼地址:[点击下載源碼](http://download.csdn.net/detail/fdipzone/5151095)
php transport,PHPMailer - PHP email transport class相关推荐
- PHPMailer - PHP email transport class
在服务器安装 sendmail sudo apt-get install sendmail 启动 sendmail sudo /etc/init.d/sendmail start 修改 php.ini ...
- elasticsearch.client.transport.TransportClientNodesService[420] - node {#transport#-1}
最近启动项目,发现一直提示 ES node问题,即elasticsearch连接客户端后,创建索引index时报错如下,提示没有获取到可用的节点. 错误信息如下: elasticsearch.clie ...
- 中文详解phpmailer所有对象和属性
2019独角兽企业重金招聘Python工程师标准>>> 2009-03-09 19:13:50 前言: phpmailer是一个优秀的发件程序,但中文资料比较少,于是有牛人手动翻 ...
- php 利用phpmailer 发送邮件
利用phpmailer 来发送邮件:需要利用到的类有:class.phpmailer.php ,发送邮件的方式主要有3种 (pop,stmp,sendmail); 一.编写的测试用例: <? ...
- PHPMailer发送邮箱
1.可以参考的链接.http://www.helloweba.com/view-blog-205.html 2.下载最新的PHPMailer文件库 3.主要代码 class.phpmailer.php ...
- phpmailer 私密抄送_phpmailer中文手册属性方法
$AltBody --属性 出自:PHPMailer::$AltBody ,文件:class.phpmailer.php 阐发 :该属性的设置是在邮件正文不支持 HTML的备用表现 AddAddres ...
- php发送邮件的新的体会。
首先,我用的是tp5框架,一下是我的步骤. 1.建一个Smtp.class.php <?php namespace phpmailer; /*~ class.smtp.php .-------- ...
- PHP实现邮件自动发送
调用邮件类的demo <?php require 'phpmailer.class.php'; $subject = 'My Subject'; $email = 'This is the co ...
- thinkPHP邮箱接口
一共四个php文件 用于测试是否成功 demo.php <?php date_default_timezone_set("PRC"); //send_mail(第一个参数收件 ...
最新文章
- MIT 6.824 Lab2A (raft) -- Leader Election
- Nginx系列~负载均衡服务器与WWW服务器的实现
- PHPStorm2016如何安装主题
- 一分钟了解 Matlab求两个矩阵的相关程度corr2
- linux c打印日志文件,linux c下log输出代码模板示例代码
- 第二章 HTML5存储 Web存储
- Day46:数据库引擎、索引、pymysql
- Linux与Windows编译器的区别
- iPhone硬件拆机解锁方法 十步!
- 玉溪第一座智能变电站,造国际一流智能配电网,机器人来运维
- sqlmap用法详解
- tesla p4 linux驱动,Ubuntu 16.04. 装tesla p4 显卡驱动+cuda9.0+docker+nvidia-docker 详细方法,这里是服务器为主...
- 无人驾驶(二)---室外导航之RTK配置与接入及GPS与UTM坐标转换
- 为什么我学51单片机很顺利,学STM32却一头雾水?
- Matlab中switch, case, otherwise语句
- npm命令配置淘宝镜像
- 淘宝关键词搜索商品API
- 机器学习——贝叶斯网(bayesian Network)一
- 印象笔记:网页版与mac客户端工具栏都不一样
- wayos维盟JMV7500河南维盟一级代理商专供四WAN全千M智能流控路由器