Use phpmailer to send the email code [send html content]

Source: Internet
Author: User
We use phpmailer to implement the Mail sending function. here we also use a template to read the content of a specified file and send it to a friend. & lt ;? Php @ session_start (); include (Dinam

We use phpmailer to implement the Mail sending function. here we also use the template to read the specified file and send it to a friend.

  1. @ Session_start ();
  2. Include (dirname (_ FILE _). './inc/function. php ');
  3. Require (dirname (_ FILE _). "/mail/class. phpmailer. php ");
  4. $ Array = array_unique (Get_value ('mail', 1 ));
  5. $ Type = Get_value ('type', 1 );
  6. $ Mail = new PHPMailer ();
  7. $ Count = 0;
  8. $ Bad = 0;
  9. $ Mail-> IsSMTP (); // set mailer to use SMTP
  10. $ Mail-> Host = "smtp.163.com"; // smtp1.example.com; smtp2.example. comspecify main and backup server
  11. $ Mail-> SMTPAuth = true; // turn on SMTP authentication
  12. $ Mail-> Username = "mailangel123"; // SMTP username
  13. $ Mail-> Password = "******"; // SMTP password
  14. $ Mail-> From = "mailangel123@163.com ";
  15. $ Mail-> FromName = "from your friends ";
  16. $ MailBody = GetContent ($ type );
  17. // $ Array = explode ('|', $ rs ['mail']);
  18. Foreach ($ array as $ tmpmail ){
  19. If (@ preg_match ("/w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) */", $ tmpmail)
  20. | Strlen ($ User_Mail) <6)
  21. {
  22. $ Mail-> AddReplyTo ("mailangel123@163.com", "44 ");
  23. $ Mail-> AddAddress ($ tmpmail, 'Hello! ');
  24. $ Mail-> WordWrap = 50;
  25. $ Mail-> CharSet = "GB2312 ";
  26. // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz ");
  27. // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg ");
  28. $ Mail-> IsHTML (true );
  29. $ Mail-> Subject = "your friends invite you to take a photo! ";
  30. $ Mail-> Body = $ MailBody;
  31. If (! $ Mail-> Send ())
  32. {
  33. $ Bad ++;
  34. $ Mail-> ClearAddresses ();
  35. $ Mail-> ClearAttachments ();
  36. }
  37. Else
  38. {
  39. $ Count ++;
  40. }
  41. }
  42. ShowMsg ("result: $ count ");
  43. }
  44. The following article reads and sends html documents,
  45. Function GetContent ($ type ){
  46. If ($ type)
  47. {
  48. If (file_exists ('./mail_room.html '))
  49. {
  50. $ Content = file_get_contents ('./mail_room.html ');
  51. }
  52. Else
  53. {
  54. ShowMsg ('file can 'read fail ');
  55. }
  56. }
  57. Else
  58. {
  59. If (file_exists ('./mail_person.html '))
  60. {
  61. $ Content = file_get_contents ('./mail_person.html ');
  62. }
  63. Else
  64. {
  65. ShowMsg ('person file read fail! ');
  66. }
  67. }
  68. Return $ content;
  69. }
  70. /* Echo "script" alert ('Sending off ". $ count." email succeeded '); script "; */
  71. ?>

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.