phpmailer is a mail sending class that is often used in PHP programming. I will introduce you to an entry-level example of using phpmailer to send mass emails. Friends in need can refer to it.
1. Create smtp_mail function phpmai.php <?php /** * PHPMailer群发邮件的例子 * Edit bbs.it-home.org */ 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 style="max-width:90%" style="max-width:90%" src='http://bbs.it-home.org/email.php?act=img&mail=".$sendto_email."&table=".$mail_table."' / alt="Getting started with PHPmailer mass mailing example" >"; 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 ""; //个人需求,可以去掉 } else { echo "$user_name 邮件发送成功!请查收邮箱确认!<br />";//发送成功 } } } ?> Copy after login 2. Email sending page 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);*///保存发送状态,可以去掉 ?> Copy after login Attached is the download address of version V5.1 of PHPMailer email sending class. |