PHP7中文手册2018 带注释 最新chm版
<?php header ( 'Content-Type: text/html; charset=utf-8' ); require ("class.phpmailer.php"); error_reporting ( E_ERROR ); $handle = fopen ( 'error.log', 'a+b' ); $mailconfig = array ( 'FromName' => '管理员', 'SMTPAuth' => true, 'CharSet' => 'utf8', 'Encoding' => 'base64' ); //Mail STMP 服务器 配置可能需要大量的账号,不然易被邮箱服务器给屏蔽掉了 $mailservers = array ( array ( 'host' => 'smtp.163.com', 'username' => 'test1@163.com', 'password' => 'test1' ),array ( 'host' => 'smtp.163.com', 'username' => 'test2@163.com', 'password' => 'test2' ),array ( 'host' => 'smtp.163.com', 'username' => 'test3@163.com', 'password' => 'test3' ) ); $counter = 0; function smtp_mail($sendto_email, $subject, $body, $att = array()) { global $handle, $mailconfig, $mailservers, $counter; $mail = new PHPMailer (); $mail->IsSMTP (); $mailserver = $mailservers [$counter % count($mailservers)]; $mail->Host = $mailserver ['host']; $mail->Username = $mailserver ['username']; $mail->Password = $mailserver ['password']; $mail->FromName = $mailconfig ['FromName']; $mail->SMTPAuth = $mailconfig ['SMTPAuth']; $mail->From = $mail->Username; $mail->CharSet = $mailconfig ['CharSet']; $mail->Encoding = $mailconfig ['Encoding']; $mail->AddAddress ( $sendto_email ); // 对附件文件的处理 foreach ( $att as $key => $val ) { if (! empty ( $val )) { $mail->AddAttachment ( $val ); // 注意要给绝对路径 } } $mail->IsHTML ( true ); $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = "text/html"; if (! $mail->Send ()) //将错误写入到错误日志文件 fwrite ( $handle, $sendto_email."--".($mail->From)."\r\n" ); else echo "邮件发送成功! $counter\n"; $counter ++; } // 邮件内容 $body = file_get_contents ( 'mail_content.php' ); for ($i=0;$i<count($mailservers);$i++){ // 参数说明(发送地址, 邮件主题, 邮件内容,附件绝对路径) //smtp_mail ( '88888@qq.com', '欢迎你的到来', $body, array ('email.txt') ); } fclose($handle); ?>
转载请注明:谷谷点程序 » PHPMailer批量发送邮件,背后的故事