Phpmailer class implements the instance code of bulk mail

Source: Internet
Author: User
Tags word wrap
  1. /**

  2. * Bulk Mail sample
  3. * Phpmailer Class Application Example
  4. */
  5. Phpmailer class file
  6. Require_once ("class.phpmailer.php");

  7. Send email 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: Normal mail authentication does not need to add @ domain name
  14. $mail->password = "1983106"; SMTP Password

  15. $mail->from = ""; Sender Mailbox

  16. $mail->fromname = "WWW.JBXUE.COM"; The sender, such as the programmer's home.

  17. $mail->charset = "GB2312"; Specify the character set here!

  18. $mail->encoding = "base64";

  19. $mail->addaddress ($sendto _email, $user _name); Recipient's mailbox and name

  20. $mail->addreplyto ("", "home of the programmer");

  21. $mail->wordwrap = 50; Set word Wrap

  22. $mail->addattachment ("/var/tmp/file.tar.gz"); Attachment Accessories 1
  23. $mail->addattachment ("/tmp/image.jpg", "new.jpg"); Annex 2
  24. $mail->ishtml (TRUE); Send As HTML
  25. $mail->subject = $subject;

  26. Message content can be sent directly to HTML file

  27. $mail->body = <<<>
  28. Phpmailer Bulk Mail Sample _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 failure, error message $mail->errorinfo");
  37. }
  38. }
  39. Send Email function end

  40. Write send 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, a);
  46. Fwrite ($fp, $info);
  47. Fclose ($FP);
  48. }

  49. Timed jump page function where 1000 is the time, 1 seconds, you can customize

  50. function redirect ($url)
  51. {
  52. echo "";
  53. }

  54. Read the text email address you can also read the database

  55. $filename = "Email.txt";
  56. $fp = fopen ($filename, "R");
  57. $contents = Fread ($fp, FileSize ($filename));
  58. $list _email=explode ("\ r \ n", $contents);
  59. $len =count ($list _email);
  60. Fclose ($FP);

  61. Parameter description (Sent to, message subject, message content, additional information, user name)

  62. $i = $_get[' action '];
  63. $i + +;
  64. if ($i < $len)
  65. {
  66. $rs =explode ("@", $list _email[$i]);
  67. $user _name = $rs [' 0 '];
  68. echo "Sending {$i} ({$list _email[$i]}) Mail ... {$user _name} ";
  69. Smtp_mail ($list _email[$i], ' treasurery Online weekly 12th ', $body, ' http://bbs.it-home.org/', $user _name);
  70. Redirect ("action= $i");
  71. }
  72. else {
  73. echo "All messages sent";
  74. Exit
  75. }
  76. ?>
Copy Code

Code Description: Read the above article Email.txt, can also be directly QQ number, each line a number, and then use Fget () read each line QQ number, finally add QQ mailbox suffix @qq. com. This clever idea, hoping to help you, huh. Attached, Phpmailer Mail Send class V5.1 download address.

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