Phpmailer class implements the instance code for mass mailing

Source: Internet
Author: User
Tags word wrap
Phpmailer class implements the instance code for mass mailing

  1. /**

  2. * Example of mass mailing
  3. * Phpmailer application instance
  4. */
  5. // PHPmailer class file
  6. Require_once ("class. phpmailer. php ");

  7. // Email sending function

  8. Function smtp_mail ($ sendto_email, $ subject, $ body, $ extra_hdrs, $ user_name ){
  9. $ Mail = new PHPMailer ();
  10. $ Mail-> IsSMTP (); // send via SMTP
  11. $ Mail-> Host = "smtp.163.com"; // SMTP servers
  12. $ Mail-> SMTPAuth = true; // turn on SMTP authentication
  13. $ Mail-> Username = "test123"; // SMTP username note: @ domain name is not required for normal mail authentication.
  14. $ Mail-& gt; Password = "1983106"; // SMTP password

  15. $ Mail-> From = ""; // sender's email

  16. $ Mail-> FromName = "WWW. JBXUE. COM"; // sender, such as programmer's house

  17. $ Mail-> CharSet = "GB2312"; // The character set is specified here!

  18. $ Mail-> Encoding = "base64 ";

  19. $ Mail-> AddAddress ($ sendto_email, $ user_name); // recipient's email address and name

  20. $ Mail-> AddReplyTo ("", "Programmer's House ");

  21. // $ Mail-> WordWrap = 50; // set word wrap

  22. // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment 1
  23. // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // Attachment 2
  24. $ Mail-> IsHTML (true); // send as HTML
  25. $ Mail-> Subject = $ subject;

  26. // The email content can be directly sent to html files

  27. $ Mail-> Body = <
  28. Phpmailer mail group example _ bbs.it-home.org
  29. EOT;
  30. $ Mail-> AltBody = "text/html ";
  31. If ($ mail-> Send ())
  32. {
  33. Info_write ("OK .txt", "$ user_name sent successfully ");
  34. }
  35. Else {
  36. Info_write ("falied.txt", "$ user_name failed, error message $ mail-> ErrorInfo ");
  37. }
  38. }
  39. // The Email sending function ends.

  40. // Write the sending result function, error log record

  41. Function info_write ($ filename, $ info_log)
  42. {
  43. $ Info. = $ info_log;
  44. $ Info. = "\ r \ n ";
  45. $ Fp = fopen ($ filename, );
  46. Fwrite ($ fp, $ info );
  47. Fclose ($ fp );
  48. }

  49. // Scheduled page jump function, where 1000 is the time, 1 second, you can customize

  50. Function redirect ($ url)
  51. {
  52. Echo "script"
  53. Function redirect ()
  54. {
  55. Window. location. replace ('$ URL ');
  56. }
  57. Window. setTimeout ('Redirect (); ', 15000 );
  58. Script ";
  59. }

  60. // Read the text email address. you can also read the database.

  61. $ Filename = "email.txt ";
  62. $ Fp = fopen ($ filename, "r ");
  63. $ Contents = fread ($ fp, filesize ($ filename ));
  64. $ List_email = explode ("\ r \ n", $ contents );
  65. $ Len = count ($ list_email );
  66. Fclose ($ fp );

  67. // Parameter description (sent to, subject, content, additional information, user name)

  68. $ I = $ _ GET ['action'];
  69. $ I ++;
  70. If ($ I <$ len)
  71. {
  72. $ Rs = explode ("@", $ list_email [$ I]);
  73. $ User_name = $ rs ['0'];
  74. Echo "sending the {$ I} ({$ list_email [$ I]}) email... {$ user_name }";
  75. Smtp_mail ($ list_email [$ I], 'treasurery Online weekly 12th ', $ body, 'http: // bbs.it-home.org/', $ user_name );
  76. Redirect ("? Action = $ I ");
  77. }
  78. Else {
  79. Echo "all emails have been sent ";
  80. Exit;
  81. }
  82. ?>

Code description. This smart idea is helpful to you. Appendix, PHPMailer mail sending class V5.1.

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.