**在服务器安装 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相关推荐

  1. PHPMailer - PHP email transport class

    在服务器安装 sendmail sudo apt-get install sendmail 启动 sendmail sudo /etc/init.d/sendmail start 修改 php.ini ...

  2. elasticsearch.client.transport.TransportClientNodesService[420] - node {#transport#-1}

    最近启动项目,发现一直提示 ES node问题,即elasticsearch连接客户端后,创建索引index时报错如下,提示没有获取到可用的节点. 错误信息如下: elasticsearch.clie ...

  3. 中文详解phpmailer所有对象和属性

    2019独角兽企业重金招聘Python工程师标准>>> 2009-03-09 19:13:50 前言:   phpmailer是一个优秀的发件程序,但中文资料比较少,于是有牛人手动翻 ...

  4. php 利用phpmailer 发送邮件

      利用phpmailer 来发送邮件:需要利用到的类有:class.phpmailer.php ,发送邮件的方式主要有3种 (pop,stmp,sendmail); 一.编写的测试用例: <? ...

  5. PHPMailer发送邮箱

    1.可以参考的链接.http://www.helloweba.com/view-blog-205.html 2.下载最新的PHPMailer文件库 3.主要代码 class.phpmailer.php ...

  6. phpmailer 私密抄送_phpmailer中文手册属性方法

    $AltBody --属性 出自:PHPMailer::$AltBody ,文件:class.phpmailer.php 阐发 :该属性的设置是在邮件正文不支持 HTML的备用表现 AddAddres ...

  7. php发送邮件的新的体会。

    首先,我用的是tp5框架,一下是我的步骤. 1.建一个Smtp.class.php <?php namespace phpmailer; /*~ class.smtp.php .-------- ...

  8. PHP实现邮件自动发送

    调用邮件类的demo <?php require 'phpmailer.class.php'; $subject = 'My Subject'; $email = 'This is the co ...

  9. thinkPHP邮箱接口

    一共四个php文件 用于测试是否成功 demo.php <?php date_default_timezone_set("PRC"); //send_mail(第一个参数收件 ...

最新文章

  1. MIT 6.824 Lab2A (raft) -- Leader Election
  2. Nginx系列~负载均衡服务器与WWW服务器的实现
  3. PHPStorm2016如何安装主题
  4. 一分钟了解 Matlab求两个矩阵的相关程度corr2
  5. linux c打印日志文件,linux c下log输出代码模板示例代码
  6. 第二章 HTML5存储 Web存储
  7. Day46:数据库引擎、索引、pymysql
  8. Linux与Windows编译器的区别
  9. iPhone硬件拆机解锁方法 十步!
  10. 玉溪第一座智能变电站,造国际一流智能配电网,机器人来运维
  11. sqlmap用法详解
  12. tesla p4 linux驱动,Ubuntu 16.04. 装tesla p4 显卡驱动+cuda9.0+docker+nvidia-docker 详细方法,这里是服务器为主...
  13. 无人驾驶(二)---室外导航之RTK配置与接入及GPS与UTM坐标转换
  14. 为什么我学51单片机很顺利,学STM32却一头雾水?
  15. Matlab中switch, case, otherwise语句
  16. npm命令配置淘宝镜像
  17. 淘宝关键词搜索商品API
  18. 机器学习——贝叶斯网(bayesian Network)一
  19. 印象笔记:网页版与mac客户端工具栏都不一样
  20. wayos维盟JMV7500河南维盟一级代理商专供四WAN全千M智能流控路由器

热门文章

  1. requests用法
  2. Jboss4集群配置之四:启动Jboss集群
  3. sas中的sql(2) 行选择 、限制重复、条件运算符、运行前语法检查、feedback、count...
  4. iptables的基础知识-iptables中的状态检测
  5. 如何在XenServer主机上安装虚拟机
  6. 如何找出SQL中的重复记录
  7. C语言:输入两个数,输出最大公约数,最小公倍数
  8. 绘图操作(点,线,多边形,徒手多边形等)
  9. NASA重金悬赏 太空尿片最佳解决方案
  10. SQL Server 2005,2008 正则表达式 替换函数应用详解