PHPMailer是一個用於發送電子郵件的PHP函數包,下載PHPMailer-master,提取裏面的4個文件:class.phpmailer.php,class.pop3.php,class.smtp.php,PHPMailerAutoload.php。而後創建個mail.php,裏面代碼以下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 = "it5808@126.com"; $mail -> Password = "。。。。"; //本身的真密碼 } //// 添加附件,並指定名稱 if(!empty($Attachment)){ $mail->AddAttachment($Attachment,'email.txt'); } $mail -> From = "it5808@126.com"; //來源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"); } ?>