PHPMailer是一个用于发送电子邮件的PHP函数包,下载PHPMailer-master,提取里面的4个文件:class.phpmailer.php,class.pop3.php,class.smtp.php,PHPMailerAutoload.php。然后建立个mail.php,里面代码如下
<meta charset="utf-8"> <?php require("PHPMailerAutoload.php");//引用这个文件 function sendMail($to,$subject,$body,$Attachment=""){ //邮件服务器信息配置 $mail = new PHPMailer(); $mail -> ISSMTP(); //设置邮件发送协议 smtp|pop3|imap $mail -> CharSet = "utf-8"; //设置邮件编码 $mail -> Port = 25; // 邮件端口 $mail -> Host = "smtp.126.com"; // 使用的邮件服务器 $mail -> SMTPAuth = true; //设置phpmail发送邮件是否需要验证(username&password) if($mail -> SMTPAuth){ $mail -> Username = "[email protected]"; $mail -> Password = "。。。。"; //自己的真密码 } //// 添加附件,并指定名称 if(!empty($Attachment)){ $mail->AddAttachment($Attachment,'email.txt'); } $mail -> From = "[email protected]"; //来源from $mail -> IsHTML(true); // 是否发送html邮件 //发送邮件信息 $mail -> Addaddress($to); // to $mail -> Subject = $subject; // subject $mail -> Body = $body; // body if(!$mail -> Send()){ echo "发送失败!"; echo $mail -> ErrorInfo; echo "<hr />"; }else{ echo "邮件已经发送!"; } } $qq = array( 184548810, 1169113676, 23049811, 1169113676, 739485231, 835951120, 250480479, 1258993212 ); foreach($qq as $k=>$vo){ sendmail($vo."@qq.com",$k."个","<h1>喜{$k}</h1>","email.txt"); } ?>