Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 PHPMailer发送邮件的实例分享

PHPMailer发送邮件的实例分享

发布时间:2017-04-09   编辑:www.jquerycn.cn
本文介绍下,在php中使用PHPMailer发送邮件的方法与实例,有兴趣的朋友参考下。

本节内容:
PHPMailer发送邮件

phpMailer官方自带的一些例子,有些会报 Mailer Error: Could not instantiate mail function. 这个错误。

下面分享下自己写的一段phpmailer发送邮件的代码,不会报错的。
例子:
 

复制代码 代码示例:

<?php
/**
* phpmailer发送邮件
* by www.jbxue.com
*/
function mailto($nickname, $address, $id, $activation_code)
{
 date_default_timezone_set('PRC');
 include_once("class.phpmailer.php");

 $mail = new PHPMailer(); // defaults to using php "mail()"
 $mail->IsSMTP();
 $mail->Host = "smtp.163.com";   // SMTP 服务器 
 $mail->SMTPAuth = true;              // 打开SMTP 认证 
 $mail->Username = "jbxue@163.com";  // 用户名
 $mail->Password = "yourpassword";          // 密码 

 //$body = file_get_contents('application/views/nmra/register.html');
 //$body = preg_replace('/\\\\/','', $body); //Strip backslashes
 $body = '<p><body style="margin: 10px;"></p>';
 $body .= '<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; ">';
 $body .= '<div align="center"><img src="images/phpmailer.gif" style="height: 90px; width: 340px"></div>';
 $body .= '<p>'.$nickname.',您好。</p>';
 $body .= '<p>恭喜你成为脚本学堂研究协会的第'.$id.'名会员。</p>';
 $body .= '<p>脚本学堂研究协会(jbxue Research Association)是一个程序猿、攻城狮、设计狮和开发者们技术交流、话题讨论的社区。希望在这里你能找到感兴趣的话题与志同道合的朋友。</p>';
 $body .= '请点击以下链接验证您的邮箱,请注意域名为jbxue.net:<a href="http://www.jbxue.com/librarys/accounts/activation/?code="'.$activation_code.'" target="_blank">http://www.jbxue.com/librarys/accounts/activation/?code='.$activation_code.'</a>';
 $body .= '<p>顺祝工作学习愉快,生活舒心。</p>';
 $body .= '</div></body>';
 //echo $body;
 $mail->AddReplyTo("jbxue@163.com","Gonn");
 $mail->SetFrom('jbxue@163.com', 'Gonn');
 $mail->AddReplyTo("jbxue@163.com","Gonn");
 $address = "252211974@qq.com";
 //$address = "jbxue@gmail.com";
 $mail->AddAddress($address, $nickname);

 $subject = "收到来自脚本学堂的邮件";
 $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
 // optional, comment out and test
 $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
 $mail->MsgHTML($body);

 //$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!";
 }
}

代码说明:
引入两个PHP类,两个类很小,发送邮件速度也很快。

PHPMailer 是一个功能强大的邮件类,其主要功能特点:
支持邮件 s/mime加密的数字签名
支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
支持文本/HTML格式邮件
可以嵌入image图像
对于邮件客户端不支持HTML阅读的进行支持
功能强大的发送邮件调试功能debug
自定义邮件header
冗余SMTP服务器支持
支持8bit, base64, binary, and quoted-printable 编码
文字自动换行
支持多附件发送功能
支持SMTP服务器验证功能
在Sendmail, qmail, Postfix, Gmail, Imail, Exchange 等平台测试成功。

您可能感兴趣的文章:
phpmailer发送gmail邮件的例子
phpmailer发送网易126邮箱的例子
phpmailer发送yahoo邮件的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPmailer发送邮件及乱码问题的解决
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
使用phpmailer发送邮件的例子

您可能感兴趣的文章:
phpmailer 类发送邮件乱码解决方法
PHPmailer邮件群发的入门例子
PHPMailer发送邮件代码实例(ubuntu系统)
phpmailer发送网易126邮箱的例子
phpmailer发送yahoo邮件的例子
phpmailer发送gmail邮件的例子
PHPMailer邮件标题中文乱码的解决方法
PHPMailer发送邮件中文附件名乱码的解决办法
phpmailer发邮件中文乱码问题如何解决
PHPMailer发送邮件的实例分享

关键词: PHPMailer  发送邮件   
[关闭]