利用PHPMailer 来完成PHP的邮件发送

1.首先是下载PHPMailer

http://code.google.com/a/apache-extras.org/p/phpmailer/

2.解压

从中取出class.phpmailer.php 和 class.smtp.php 放到你的项目的文件夹,因为我们等下会引用到它们.

3.创建发送邮件的函数,其中你需要配置smtp服务器

function postmail($to,$subject = '',$body = ''){

    //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('Asia/Shanghai');//设定时区东八区
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(); //new一个PHPMailer对象出来
$body = preg_replace("#[\]#",'',$body); //对邮件内容进行必要的过滤
$mail->CharSet ="GBK";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 1; // 启用SMTP调试功能
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->SMTPSecure = "ssl"; // 安全协议,可以注释掉
$mail->Host = 'stmp.163.com'; // SMTP 服务器
$mail->Port = 25; // SMTP服务器的端口号
$mail->Username = 'wangliang_198x'; // SMTP服务器用户名,PS:我乱打的
$mail->Password = 'password'; // SMTP服务器密码
$mail->SetFrom('xxx@xxx.xxx', 'who');
$mail->AddReplyTo('xxx@xxx.xxx','who');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
// echo "Message sent!恭喜,邮件发送成功!";
}
}

4. 使用函数

postmail('wangliang_198x@163.com','My subject','哗啦啦');

利用PHPMailer 来完成PHP的邮件发送 #转载自:大菜鸟在云端#的更多相关文章

  1. 利用PHPMailer 来完成PHP的邮件发送

    翻起之前的代码看了一下,还是发表到这里,以后容易查找. 以下的两个文件在这里下载 http://download.csdn.net/detail/u013085496/9673828 也可以直接上gi ...

  2. PHP中利用PHPMailer使用QQ邮箱实现邮件发送

    /** * 下订单发送邮件 * @to 收件人 @title 标题 @content 内容 */ function sendMail($to,$title,$content){ //引入PHPMail ...

  3. springboot利用mail配置包,实现邮件发送

    了解邮件发送与接收的过程: A->S1->S2->B 1.计算机A通过SMTP协议将邮件发送到服务器S1上: 2.服务器S1再发送到服务器S2: 3.计算机B通过POP3协议接收服务 ...

  4. phpMailer在thinkPHP框架中邮件发送

    资源下载地址:http://pan.baidu.com/s/1c0kAoeO 提取码:ry5v 关键代码:application/Common/Common/funciton.php <?php ...

  5. 利用System.Net.Mail和多线程实现邮件发送

    对于邮件发送,一般来说,程序会响应超过1秒,这样对于用户体验来说,让用户等待的时间过长,而且发送的邮件越多时间就越长,所以这里我利用了线程的来处理邮件发送这种耗时的工作,废话不多说,直接上代码 pri ...

  6. 【Thinkphp 5】 整合邮箱类 phpmailer实现邮件发送

    第一步:下载phpmailer文件,主要用到的文件只有箭头指向的两个,thinkphp5中,把class.phpmailer.php改成了phpmailer.php 第二步: 将phpmailer文件 ...

  7. 利用phpmailer类邮件发送

    <?php require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new PHPMailer(); //建立邮 ...

  8. TP5实现邮件发送(PHP 利用QQ邮箱发送邮件「PHPMailer」)

    在 PHP 应用开发中,往往需要验证用户邮箱.发送消息通知,而使用 PHP 内置的 mail() 函数,则需要邮件系统的支持. 如果熟悉 IMAP/SMTP 协议,结合 Socket 功能就可以编写邮 ...

  9. phpMailer邮件发送

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 2016 年青岛网络赛---Tea

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5881 Problem Description Tea is good. Tea is life. Te ...

  2. 编译安装php-amq扩展

    用途:这个扩展是用来操作rabbitmq服务端的 一.安装总括 1.编译安装librabbitmq库 这是一个开源c语言的库.用来与rabbitmq进行通信 而php的php-amqp扩展就是使用这个 ...

  3. JavaScript对象(Object)

         JavaScript的简单数据类型包括数字.字符串.布尔值.null值和undefined值,其他所有的值都是对象.数字.字符串.布尔值“貌似”对象,因为他们拥有方法,但是他们是不可变的. ...

  4. cnodejs社区论坛3--发表话题

  5. Codrops 实验:使用 Vibrant.js 提取图像颜色

    Codrops 分享了一个有趣的颜色提取实验.这个想法是创建图像的调色板,既有图像本身的潜移默化的影响,也有一些花哨的颜色延伸.通过使用 Vibrant.js 来提取图像中的颜色,并通过 CSS 过滤 ...

  6. 【精心推荐】几款极好的 JavaScript 文件上传插件

    文件上传功能作为网页重要的组成部分,几乎无处不在,从简单的单个文件上传到复杂的批量上传.拖放上传,需要开发者花费大量的时间和精力去处理,以期实现好用的上传功能.这篇文章向大家推荐几款很棒的 JavaS ...

  7. Plyr – 简单,灵活的 HTML5 媒体播放器

    Plyr 是一个简单的 HTML5 媒体播放器,包含自定义的控制选项和 WebVTT 字幕.它是只支持现代浏览器,轻量,方便和可定制的媒体播放器.还有的标题和屏幕阅读器的全面支持. 在线演示      ...

  8. [deviceone开发]-动画示例源码

    一.简介 do_FrameAnimtionView组件是用加载GIF动态图片和加载一系列图片形成动画效果的展示组件,这个示例直观的展示组件基本的使用方式.适合初学者. 二.效果图 三.相关讨论 htt ...

  9. 应用代理 socket TCP协议 的资料

    http://blog.csdn.net/guowake/article/details/6615728 Linux下高并发socket最大连接数所受的各种限制 http://stackoverflo ...

  10. 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved

    "This file could not be checked in because the original version of the file on the server was m ...