在服务器安装 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

<?php
/* 调用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;?>

源碼地址:点击下載源碼

转载于:https://www.cnblogs.com/fdipzone/archive/2013/03/17/3715132.html

PHPMailer - PHP email transport class相关推荐

  1. php transport,PHPMailer - PHP email transport class

    **在服务器安装 sendmail** ~~~ sudo apt-get install sendmail ~~~ **启动 sendmail** ~~~ sudo /etc/init.d/sendm ...

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

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

  3. php 利用phpmailer 发送邮件

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

  4. PHPMailer发送邮箱

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

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

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

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

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

  7. PHP实现邮件自动发送

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

  8. thinkPHP邮箱接口

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

  9. thinkphp3.2 实现 Phpmailer 发送邮件 配置

    环境配置如下: PHp版本:5.4.27 ThinkPhp 框架 3.2 Apache 2.4.9 使用的是 Xampp 集成的环境 第一步: 我们建立一个 NewsController.class ...

最新文章

  1. python3安装常见问题_Python3下安装spyder及常见问题解决
  2. 报告:美国AI投资占全球56% 中国第二增长最快
  3. 场景切换 异步加载 loading条做法
  4. 阿里产品专家杨文韬:你想了解的1688都在这里
  5. from flask.ext.cache import make_template_fragment_key
  6. 期货与期权(part1)--衍生品
  7. 在iOS8 下用Swift 创建自定义的键盘
  8. powershell some check
  9. POJ 2965 开冰箱的门(回溯)
  10. 字节软件测试岗二面:APP测试问题被虐哭了,直到看到这些知识点
  11. linux命令kill_什么是Linux中的kill命令?
  12. mysql分析语句方法_Mysql分析-常用分析语句总结
  13. AllyCAD v3.5 R12 1CD(专业CAD软件)
  14. gd32f450 linux,GD32F450开发板初体验
  15. ]计算机专业就业方向 .
  16. R 单样本wilcoxon test
  17. 简单介绍红白机的发声系统以及其它音源 MMC
  18. Matlab 颜色、线型、标记符号和希腊字母表
  19. gateway+vue实现防接口重放、防篡改
  20. ubuntu20.04 双显卡安装

热门文章

  1. uva 12589——Learning Vector
  2. golang实现聊天室(二)
  3. redis源码剖析(十四)—— dump.rdb文件分析工具
  4. arm-linux 交叉编译 mp4v2
  5. 【数据库】数据模型基础概念(图文版)
  6. 现在做Android开发有前途吗?社招面试心得
  7. 计算机网络与网站设计知识点,计算机网络技术知识点总结-20210525075410.docx-原创力文档...
  8. mysql oracle 表空间大小_最简单的查询表空间的使用量、剩余量的方法 - Focus on Oracle、MySQL and GNU/Linux...
  9. mysql 导入dbm文件_DBM数据导入到mysql数据库方法
  10. Laravel 除了首页能正常访问,其它页面均404