PHP implements the source code _ php skills for mass mailing

Source: Internet
Author: User
Tags word wrap
This article provides a detailed analysis of the code for sending mass emails using PHP. For more information, see The code is as follows:


// 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.