PHP source code 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

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 to access the QQ number and Hong Kong Space in the U.S. space and the Hong Kong virtual host. Then, use fget () to read the QQ number and Hong Kong Space in each line, and 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.