Heim  >  Artikel  >  Backend-Entwicklung  >  phpMailer使用简单例子

phpMailer使用简单例子

WBOY
WBOYOriginal
2016-07-25 08:52:521185Durchsuche
本文介绍了phpmailer邮件类的简单用法,一个phpmailer类的简单例子,作入phpmailer类库的入门参考,需要的朋友可以看看。

在php编程中经常需要发送邮件,比如用户注册的邮件提醒等,可以使用一个很好的开源模块:phpmailer,此模块功能比较全面,支持SMTP验证。

使用方法: 1,下载phpmailer模块: 官方网站 http://www.phpdoc.org/

2,解压到一个文件夹

3,在php文件中包含 require_once("class.phpmailer.php");

4,使用smtp发送邮件(phpmailer发送邮件的例子):

$mail = new PHPMailer();     //得到一个PHPMailer实例

$mail->CharSet = "gb2312";  //设置采用gb2312中文编码
$mail->IsSMTP();   //设置采用SMTP方式发送邮件
$mail->Host = "192.168.1.27";    //设置邮件服务器的地址
$mail->Port = 25;  //设置邮件服务器的端口,默认为25

$mail->From     = "mailFrom@tencent.com";  //设置发件人的邮箱地址
$mail->FromName = "samzhang";  //设置发件人的姓名
//$mail->SMTPAuth = true;  //设置SMTP是否需要密码验证,true表示需要

$mail->Username="samzhang";

$mail->Password = 'your password";
$mail->Subject = $subject;  //设置邮件的标题

$mail->AltBody = "text/html"; // optional, comment out and test

$mail->Body = "你的邮件的内容";                    

$mail->IsHTML(true);  //设置内容是否为html类型
//$mail->WordWrap = 50;   //设置每行的字符数
$mail->AddReplyTo("samzhang@tencent.com","samzhang");     //设置回复的收件人的地址
$mail->AddAddress("mailTo@tencent.com","toName");     //设置收件的地址
if(!$mail->Send()) {    //发送邮件
  echo 发送失败:';
 } else {
  echo "发送成功;


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn