Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 PHPmailer邮件群发的入门例子

PHPmailer邮件群发的入门例子

发布时间:2016-01-12   编辑:www.jquerycn.cn
phpmailer是php编程中经常用得到的mail发送类,为大家介绍一个入门级的例子,用phpmailer进行邮件群发,有需要的朋友,可以参考下。

1、创建smtp_mail函数 phpmai.php

<?php
/**
 * PHPMailer群发邮件的例子
 * Edit www.jbxue.com
*/
require("PHPMailer/class.phpmailer.php");//调用phpmailer

function smtp_mail ($sendto_email, $subject, $body, $extra_hdrs, $user_name,$host,$mailname,$mailpass,$text,$mail_table) {
$mail = new PHPMailer();
$mail->IsSMTP();                // send via SMTP
$mail->Host = $host; // SMTP servers
$mail->SMTPAuth = true;         // turn on SMTP authentication
$mail->Username =$mailname;   // SMTP username  注意:普通邮件认证不需要加 @域名
$mail->Password =$mailpass;        // SMTP password
$mail->From = $mailname;      // 发件人邮箱
$mail->FromName =  "wangkan";  // 发件人

$mail->CharSet = "gb2312";            // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"hello");  // 收件人邮箱和姓名
//$mail->AddBCC("邮箱", "ff");
//$mail->AddBCC("邮箱", "ff");这些可以暗送
//$mail->AddReplyTo("test@jbxue.com","aaa.com");
//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/qita/htestv2.rar"); // 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true);  // send as HTML
// 邮件主题
$mail->Subject = $subject;
// 邮件内容
$mail->Body =$text;
                                                                
$mail->AltBody ="text/html";
if(!$mail->Send())
{
$error=$mail->ErrorInfo;
/*if($error=="smtpnot")//自定义错误,没有连接到smtp,掉包的情况,出现这种情况可以重新发送
{
sleep(2);
$song=explode("@",$sendto_email);
$img="<img height='0' width='0' src='http://www.jbxue.com/email.php?act=img&mail=".$sendto_email."&table=".$mail_table."' />";
smtp_mail($sendto_email,"发送".$song[0].$biaoti, 'NULL', 'abc',$sendto_email,$host,$mailname,$mailpass,
$img."发送".$song[0].$con,'$mail_table');//发送邮件
}*/
 $sql="insert into error(error_name,error_mail,error_smtp,error_time,error_table) values('$error','$sendto_email','$mailname',now(),'$mail_table')";
 $query=mysql_query($sql);//发送失败把错误记录保存下来
}
else {
  if($mailname=="aaa@jbxue.com")
  {
  echo "<script type='text/javascript'>alert('".$user_name."邮件发送成功!请查收邮箱点击确认!');window.close();</script>"; //个人需求,可以去掉
  }
  else
  {
     echo "$user_name 邮件发送成功!请查收邮箱确认!<br />";//发送成功
  }
}
}
?>

2、邮件发送页 send.php

<?php
include("phpmail.php");

sleep(3);

smtp_mail($mail,"发送".$song[0].$biaoti, 'NULL', 'abc',$mail,$host,$mailname,$mailpass,$img."发送".$song[0].$con,$mail_table);//发送邮件
/*$upsql="update zhuangtai set jlid='$row[0]',zhuangtai=1,biaoti='$biaoti' where biao='$mail_table'";
$upquery=mysql_query($upsql);*///保存发送状态,可以去掉
?>

附,PHPMailer邮件发送类V5.1版下载地址。
 

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

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

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