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 = ''){
//Author:Jiucool WebSite: http://www.jiucool.com
//$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 = eregi_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 = 'userpp007'; // 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','哗啦啦');

注意充当SMTP邮箱设置,打开SMTP以及POP3服务

PHPMailer实现PHP邮件发送的更多相关文章

  1. 利用PHPMailer 来完成PHP的邮件发送 #转载自:大菜鸟在云端#

    利用PHPMailer 来完成PHP的邮件发送 1.首先是下载PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/ 2.解 ...

  2. phpMailer邮件发送

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

  3. php邮件发送 phpmailer

    首先要安装phpmailer开源项目. 将class.phpmailer.php转移到php文件夹下, 编写代码: <?php require("class.phpmailer.php ...

  4. 利用phpmailer类邮件发送

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

  5. Tp5.0 PHPMailer邮件发送

    今天突然想起来邮件发送,就看了一下PHPmailer,其实这个用起来很简单,都是封装好的 https://github.com/PHPMailer/PHPMailer,直接下载下来之后,把他放入TP5 ...

  6. TP5使用phpmailer实现邮件发送

    1.从github下载PHPMailer,在vendor目录中新建文件夹phpmailer,将压缩包中的class.phpmailer.php和class.smtp.php复制到phpmailer中, ...

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

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

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

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

  9. php 邮件发送利器 PHPMailer

    php 自带的邮件发送函数已经弱到不能用了. PHPMailer非常的强大. 绝对是php里必须使用的程序. 下载地址: https://github.com/Synchro/PHPMailer 只要 ...

随机推荐

  1. c++代码的陪伴下----菜鸟的转变

    在c++代码的陪伴下快乐的长大 学了c++也快一年了,在这里把自己的心得体会说一下吧. 1.感觉自己这一年做过的代码行数也不少,博客点击量和浏览量却不是很多,可能是自己所编的程序里面都是很基础的吧,对 ...

  2. javascript代码实现简单的五星评价功能!

    <script type="text/javascript"> //★ var spans=document.getElementsByTagName("sp ...

  3. .NET 基础 一步步 一幕幕[面向对象之堆、栈、引用类型、值类型]

    堆.栈.引用类型.值类型 内存分为堆和栈(PS:还有一种是静态存储区域 [内存分为这三种]),值类型的数据存储在栈中,引用类型的数据存储在堆中. 堆.栈: 堆和栈的区别: 栈是编译期间就分配好的内存空 ...

  4. JSON反序列化实体类

    1.定义实体类 [DataContract] public class CustomerWordOrderViewModel { [DataMember] public string Name; [D ...

  5. Java基础知识之文件操作

    流与文件的操作在编程中经常遇到,与C语言只有单一类型File*即可工作良好不同,Java拥有一个包含各种流类型的流家族,其数量超过60个!当然我们没必要去记住这60多个类或接口以及它们的层次结构,理解 ...

  6. ShopNC_WAP

    记录 ShopNC_WAP 端点点滴滴 插件记录 1.  http://www.jiawin.com/swipe-mobile-touch-slider   swiper 插件 2. https:// ...

  7. 如何得到AdoConnection.execute(sqlstr)执行的返回结果

    如何得到AdoConnection.execute(sqlstr)执行的返回结果? 1: TAdoConnection.execute有procedure.function的两种定义,function ...

  8. mongodb tip-1

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px "Helvetica Neue"; color: #454545 } p. ...

  9. android 控件ui

    公共参数: android:id="@+id/text_view"  给当前控件定义了 一个唯一标识符如:text_view android:layout_width=" ...

  10. 【故障】当Eclipse打不开的时候

    某天,当你打开Eclipse的时候,弹出这种路径错误的界面.那么,该怎么办呢??? 参考: https://zhidao.baidu.com/question/1497777962705951219. ...