phpmailer发送gmail邮件实例详解


Posted in PHP onJune 24, 2013
<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "***@gmail.com";  // GMAIL username
$mail->Password   = "***";            // GMAIL password
$mail->SetFrom('****@gmail.com', 'First Last');
$mail->AddReplyTo("***@gmail.com","First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "***@gmail.com";
$mail->AddAddress($address, "John Doe");
$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!";
}
?>
</body>
</html>
PHP 相关文章推荐
PHP网站基础优化方法小结
Sep 29 PHP
cmd下运行php脚本
Nov 25 PHP
php 无限级缓存的类的扩展
Mar 16 PHP
php download.php实现代码 跳转到下载文件(response.redirect)
Aug 26 PHP
php关于array_multisort多维数组排序的使用说明
Jan 04 PHP
thinkphp使用literal防止模板标签被解析的方法
Nov 22 PHP
php实现paypal 授权登录
May 28 PHP
PHP 7.0.2 正式版发布
Jan 08 PHP
CI框架无限级分类+递归的实现代码
Nov 01 PHP
yii2.0整合阿里云oss删除单个文件的方法
Sep 19 PHP
PHP实现的pdo连接数据库并插入数据功能简单示例
Mar 30 PHP
PHP超全局变量实现原理及代码解析
Sep 01 PHP
深入php中var_dump方法的使用详解
Jun 24 #PHP
php中让上传的文件大小在上传前就受限制的两种解决方法
Jun 24 #PHP
解析在apache里面给php写虚拟目录的详细方法
Jun 24 #PHP
关于file_get_contents返回为空或函数不可用的解决方案
Jun 24 #PHP
解析php addslashes()与addclashes()函数的区别和比较
Jun 24 #PHP
解析PHP中ob_start()函数的用法
Jun 24 #PHP
关于ob_get_contents(),ob_end_clean(),ob_start(),的具体用法详解
Jun 24 #PHP
You might like
图片存储与浏览一例(Linux+Apache+PHP+MySQL)
2006/10/09 PHP
destoon首页调用求购供应信息的地区名称的方法
2014/08/21 PHP
jquery获取多个checkbox的值异步提交给php的方法
2015/06/24 PHP
[原创]解决wincache不支持64位PHP5.5/5.6的问题(提供64位wincache下载)
2016/06/22 PHP
Javascript实现DIV滚动自动滚动到底部的代码
2012/03/01 Javascript
千分位数字格式化(用逗号隔开 代码已做了修改 支持0-9位逗号隔开)的JS代码
2013/12/05 Javascript
js获取图片宽高的方法
2015/11/25 Javascript
javascript精确统计网站访问量实例代码
2015/12/19 Javascript
jquery使用Cookie和JSON记录用户最近浏览历史
2016/04/19 Javascript
Vue.js每天必学之内部响应式原理探究
2016/09/07 Javascript
微信小程序 新建登录页并实现tabBar隐藏
2017/06/13 Javascript
Vue源码解读之Component组件注册的实现
2018/08/24 Javascript
node.js使用免费的阿里云ip查询获取ip所在地【推荐】
2018/09/03 Javascript
vue中的router-view组件的使用教程
2018/10/23 Javascript
微信小程序地图实现展示线路
2020/07/29 Javascript
[04:31]2016国际邀请赛中国区预选赛妖精采访
2016/06/27 DOTA
Python查找函数f(x)=0根的解决方法
2015/05/07 Python
python使用正则表达式替换匹配成功的组并输出替换的次数
2017/11/22 Python
python批量赋值操作实例
2018/10/22 Python
使用python itchat包爬取微信好友头像形成矩形头像集的方法
2019/02/21 Python
在macOS上搭建python环境的实现方法
2019/08/13 Python
Python中断多重循环的几种方式详解
2020/02/10 Python
Python 写了个新型冠状病毒疫情传播模拟程序
2020/02/14 Python
python实现opencv+scoket网络实时图传
2020/03/20 Python
Keras—embedding嵌入层的用法详解
2020/06/10 Python
HTML5超文本标记语言的实现方法
2020/09/24 HTML / CSS
美国女性服饰销售网站:Nasty Gal(坏女孩)
2016/07/26 全球购物
写自荐信有哪些不宜?
2013/10/17 职场文书
艺术应用与设计个人的自我评价
2013/11/23 职场文书
偷看我的初中毕业鉴定
2014/01/29 职场文书
绘画专业自荐信范文
2014/02/23 职场文书
出生公证委托书
2014/04/03 职场文书
财产公证书
2014/04/10 职场文书
营销计划书
2015/01/17 职场文书
个人廉洁自律总结
2015/03/06 职场文书
Python编写nmap扫描工具
2021/07/21 Python