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 = ''){
//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邮件发送的更多相关文章
- 利用PHPMailer 来完成PHP的邮件发送 #转载自:大菜鸟在云端#
利用PHPMailer 来完成PHP的邮件发送 1.首先是下载PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/ 2.解 ...
- phpMailer邮件发送
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- php邮件发送 phpmailer
首先要安装phpmailer开源项目. 将class.phpmailer.php转移到php文件夹下, 编写代码: <?php require("class.phpmailer.php ...
- 利用phpmailer类邮件发送
<?php require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new PHPMailer(); //建立邮 ...
- Tp5.0 PHPMailer邮件发送
今天突然想起来邮件发送,就看了一下PHPmailer,其实这个用起来很简单,都是封装好的 https://github.com/PHPMailer/PHPMailer,直接下载下来之后,把他放入TP5 ...
- TP5使用phpmailer实现邮件发送
1.从github下载PHPMailer,在vendor目录中新建文件夹phpmailer,将压缩包中的class.phpmailer.php和class.smtp.php复制到phpmailer中, ...
- 【Thinkphp 5】 整合邮箱类 phpmailer实现邮件发送
第一步:下载phpmailer文件,主要用到的文件只有箭头指向的两个,thinkphp5中,把class.phpmailer.php改成了phpmailer.php 第二步: 将phpmailer文件 ...
- TP5实现邮件发送(PHP 利用QQ邮箱发送邮件「PHPMailer」)
在 PHP 应用开发中,往往需要验证用户邮箱.发送消息通知,而使用 PHP 内置的 mail() 函数,则需要邮件系统的支持. 如果熟悉 IMAP/SMTP 协议,结合 Socket 功能就可以编写邮 ...
- php 邮件发送利器 PHPMailer
php 自带的邮件发送函数已经弱到不能用了. PHPMailer非常的强大. 绝对是php里必须使用的程序. 下载地址: https://github.com/Synchro/PHPMailer 只要 ...
随机推荐
- Android---控制设备照相机
本文译自:http://developer.android.com/training/camera/cameradirect.html 本文中,我们讨论如何使用框架API来直接的控制照相机硬件. 直接 ...
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)的解决方法
在连接数据库时,报这个错误,是/var/lib/mysql/ 目录下没有mysql.sock文件,在服务器搜索myslq.sock文件,我的是在/tmp/mysql.sock 解决方法是加一个软链: ...
- css学习笔记1
:before,:after伪元素 伪元素特性(目前已经遇到的) 它不存在于文档中,所以js无法操作它 它属于主元素本身,有些伪类仅仅是代表元素内容的一部分,譬如:first-letter代表第一个字 ...
- trove taskmanger api
trove-taskmanager服务在配置实例,管理实例的生命周期以及对数据库实例执行操作方面做了很多工作.taskmanager会通过Nova.Swift的API访问Openstack基础的服务, ...
- Android Tips
(1).设置图片缓存大小,一般可以设置为内存的1/8 int memoryCache = (int) (Runtime.getRuntime().maxMemory() / 8); (2). (3). ...
- 关于map()与filter()
def f1(a): if a == 3: pass else: return a*a li = [1,2,3,4] for i in filret(f1,li) print(i) def f1(a) ...
- Chapter 21_3 模式
很多地方都会看到各种匹配模式,每次接触这些函数,颇使人望文生畏. 今天就来好好面对它.认识它.了解它.最后战胜它. 匹配模式都是用一串常规的字符串来描述,最主要的是理解这些字符串的语法及含义(即它能匹 ...
- js 中的 exec( )方法
JavaScript exec() 方法 JavaScript RegExp 对象 定义和用法 exec() 方法用于检索字符串中的正则表达式的匹配. 语法:RegExpObject.exec(str ...
- schemes-universalLink-share_IOS-android-WeChat-chunleiDemo
schemes-universalLink-share_IOS-android-WeChat-chunleiDemo The mobile terminal share page start APP ...
- [转]Python跳过第一行读取文件内容
from itertools import islice file_name='XXXX' input_file = open(file_name) for line in islice(input_ ...