解析php中用PHPMailer来发送邮件的示例(126.com的例子)

yipeiwu_com6年前PHP代码库
<?php
require_once('../class.phpmailer.php');
$mail= new PHPMailer();
$body= "我终于发送邮件成功了!呵呵!goodboy xxxxxxx!<br/><a>http://news.qq.com/a/20111115/000792.htm?qq=0&ADUIN=594873950&ADSESSION=1321316731&ADTAG=CLIENT.QQ.3493_.0</a>";
//采用SMTP发送邮件
$mail->IsSMTP();
//邮件服务器
$mail->Host       = "smtp.126.com";
$mail->SMTPDebug  = 0;
//使用SMPT验证
$mail->SMTPAuth   = true;
//SMTP验证的用户名称
$mail->Username   = "xxxxxxx@126.com";
//SMTP验证的秘密
$mail->Password   = "password";
//设置编码格式
$mail->CharSet  = "utf-8";
//设置主题
$mail->Subject    = "测试";
//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
//设置发送者
$mail->SetFrom('xxxxxxx@126.com', 'test');
//采用html格式发送邮件
$mail->MsgHTML($body);
//接受者邮件名称
$mail->AddAddress("xxxxxxx@126.com", "test");//发送邮件
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

相关文章

wordpress自定义标签云与随机获取标签的方法详解

wp_tag_cloud() 函数的作用是用来标签云的,可以根据每个标签所关联的文章次数来定义字体大小、标签排序等属性。从 2.8 版本开始,添加了 分类法(taxonomy)参数,这就...

解析file_get_contents模仿浏览器头(user_agent)获取数据

什么是user agentUser Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本、CPU 类型、浏览器及版本、浏览器渲染引擎、...

php接口与接口引用的深入解析

1、接口的介绍与创建 关键字 :interface 2、接口的引用与规范 关键字 :implements 接口:一种成员属性全...

php计算到指定日期还有多少天的方法

本文实例讲述了php计算到指定日期还有多少天的方法。分享给大家供大家参考。具体如下: function countdays($d) { $olddate = substr($d,...

php自动给文章加关键词链接的函数代码

复制代码 代码如下: <?php $link = array( '百度,http://www.baidu.com/', '服务器软件,http://s.jb51.net/', '【...