This article provides a detailed analysis of the code for sending mass emails using PHP, for more information, see this article.
// Request the PHPmailer class file
Require_once ("class. phpmailer. php ");
// Email sending function
Function smtp_mail ($ sendto_email, $ subject, $ body, $ extra_hdrs, $ user_name ){
$ Mail = new PHPMailer ();
$ Mail-> IsSMTP (); // send via SMTP
$ Mail-> Host = "smtp.163.com"; // SMTP servers
$ Mail-> SMTPAuth = true; // turn on SMTP authentication
$ Mail-> Username = "jessiejl"; // SMTP username note: @ domain name is not required for normal mail authentication.
$ Mail-& gt; Password = "1983106"; // SMTP password
$ Mail-> From = ""; // sender's email
$ Mail-> FromName = "WWW. NIUTW. COM"; // sender, such as the beautiful build network
$ Mail-> CharSet = "GB2312"; // The character set is specified here!
$ Mail-> Encoding = "base64 ";
$ Mail-> AddAddress ($ sendto_email, $ user_name); // recipient's email address and name
$ Mail-> AddReplyTo ("", "Web Home ");
// $ Mail-> WordWrap = 50; // set word wrap
// $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment 1
// $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // Attachment 2
$ Mail-> IsHTML (true); // send as HTML
$ Mail-> Subject = $ subject;
// The email content can be directly sent to html files
$ Mail-> Body = <
Treasurery Online weekly
EOT;
$ Mail-> AltBody = "text/html ";
If ($ mail-> Send ())
{
Info_write ("OK .txt", "$ user_name sent successfully ");
}
Else {
Info_write ("falied.txt", "$ user_name failed, error message $ mail-> ErrorInfo ");
}
}
// The Email sending function ends.
// Write the sending result function, error log record
Function info_write ($ filename, $ info_log)
{
$ Info. = $ info_log;
$ Info. = "\ r \ n ";
$ Fp = fopen ($ filename, );
Fwrite ($ fp, $ info );
Fclose ($ fp );
}
// Scheduled page jump function, where 1000 is the time, 1 second, you can customize
Function redirect ($ url)
{
Echo "script"
Function redirect ()
{
Window. location. replace ('$ URL ');
}
Window. setTimeout ('Redirect (); ', 15000 );
Script ";
}
// Read the text email address. you can also read the database.
$ Filename = "email.txt ";
$ Fp = fopen ($ filename, "r ");
$ Contents = fread ($ fp, filesize ($ filename ));
$ List_email = explode ("\ r \ n", $ contents );
$ Len = count ($ list_email );
Fclose ($ fp );
// Parameter description (sent to, subject, content, additional information, user name)
$ I = $ _ GET ['action'];
$ I ++;
If ($ I <$ len)
{
$ Rs = explode ("@", $ list_email [$ I]);
$ User_name = $ rs ['0'];
Echo "sending the {$ I} ({$ list_email [$ I]}) email... {$ user_name }";
Smtp_mail ($ list_email [$ I], 'treasurery Online weekly 12th ', $ body, 'http: // www.yem120.com/', $ user_name );
Redirect ("? Action = $ I ");
}
Else {
Echo "all emails have been sent ";
Exit;
}
?>
Tips:
You can also use the QQ number for reading the document "email.txt". each line has a number, and then use fget () to read the QQ number of each line. Then, add the QQ mailbox suffix @ qq.com.