e-mail delivery with open source project Phpmailer

Source: Internet
Author: User
This is to use open source project Phpmailer to achieve the mail, first download the file, I download it here is 5.1 version, and then put three class.***.php files into the project file, I first use is Gmail, but failed, the problem is authentication failure, later used QQ mailbox, send success.
  1. Require ("class.phpmailer.php"); The downloaded file must be placed in the directory where the file is located
  2. $mail = new Phpmailer (); Set up a mail sending class
  3. $address = "youbinliu@126.com";
  4. $mail->issmtp (); Send using SMTP mode
  5. $mail->host = "smtp.qq.com"; Your enterprise Post office domain name
  6. $mail->smtpauth = true; Enable the SMTP authentication feature
  7. $mail->username = "843831601@qq.com"; Post Office User name (please fill in the full email address)
  8. $mail->password = "***********"; Post Office password
  9. $mail->port=25;
  10. $mail->from = "843831601@qq.com"; Email Sender Email Address
  11. $mail->fromname = "Liuyoubin";
  12. $mail->addaddress ("$address", "a");//recipient address, can be replaced with any email message you want to receive, in the format addaddress ("Recipient Email", "Recipient Name")
  13. $mail->addreplyto ("," "");
  14. $mail->addattachment ("/var/tmp/file.tar.gz"); Add an attachment
  15. $mail->ishtml (TRUE); Set email format to HTML//whether HTML is used
  16. $mail->subject = "phpmailer test mail"; Message header
  17. $mail->body = "Hello, this is Test mail"; Message content
  18. $mail->altbody = "The body in plain text for non-html mail clients"; Additional information, you can omit
  19. if (! $mail->send ())
  20. {
  21. echo "message failed to send.

    ";

  22. echo "Error Reason:". $mail->errorinfo;
  23. Exit
  24. }
  25. echo "Mail sent successfully";
  26. /*************************************************
  27. Attachment:
  28. Phpmailer instructions for use in Chinese (simplified version)
  29. A begins with:
  30. $AltBody--Properties
  31. Derived from: Phpmailer:: $AltBody
  32. Files: class.phpmailer.php
  33. Description: The setting of this property is an alternate display of HTML that is not supported in the message body
  34. addaddress--method
  35. Derived from: phpmailer::addaddress (), File: class.phpmailer.php
  36. Note: Increase the recipient. Parameter 1 is the recipient's mailbox, and Parameter 2 is the recipient's salutation. Example AddAddress ("eb163@eb163.com", "eb163"), but parameter 2 is optional, addaddress (eb163@eb163.com) is also possible.
  37. Function prototype: Public function addaddress ($address, $name = ") {}
  38. addattachment--method
  39. Derived from: Phpmailer::addattachment ()
  40. File: class.phpmailer.php.
  41. Note: Add attachments.
  42. Parameters: Path, name, encoding, type. Where the path is required and the other is optional
  43. Function Prototypes:
  44. AddAttachment ($path, $name = ', $encoding = ' base64 ', $type = ' Application/octet-stream ') {}
  45. addbcc--method
  46. Derived from: PHPMAILER::ADDBCC ()
  47. Files: class.phpmailer.php
  48. Description: Add a secret send. For the difference between CC and BCC, see [the difference between BCC and CC in SMTP senders].
  49. The parameter 1 is the address, and the parameter 2 is the name. Note This method only supports the use of SMTP under Win32, and does not support the mail function
  50. Function prototype: Public function addbcc ($address, $name = ") {}
  51. ADDCC--Methods
  52. Derived from: PHPMAILER::ADDCC ()
  53. Files: class.phpmailer.php
  54. Note: Add a CC. For the difference between CC and BCC, see [the difference between BCC and CC in SMTP senders].
  55. Parameter 1 is address, parameter 2 is name note This method supports SMTP only with Win32, and does not support mail functions
  56. Function prototype: Public function ADDCC ($address, $name = ") {}
  57. addcustomheader--method
  58. Derived from: Phpmailer::addcustomheader ()
  59. Files: class.phpmailer.php
  60. Description: Add a custom e-mail header.
  61. parameter is header information
  62. Function prototype: Public function Addcustomheader ($custom _header) {}
  63. Addembeddedimage--Methods
  64. Derived from: Phpmailer::addembeddedimage ()
  65. Files: class.phpmailer.php
  66. Description: Add an embedded image
  67. Parameters: path, return handle [, Name, encoding, type]
  68. Function prototype: Public function Addembeddedimage ($path, $cid, $name = ", $encoding = ' base64 ', $type = ' Application/octet-stream ') { }
  69. Tip: Addembeddedimage (Picture_path. "Index_01.jpg", "img_01", "index_01.jpg");
  70. Referencing in HTML
  71. addreplyto--method
  72. Originating from: Phpmailer:: Addrepl
  73. *************************************************/
  74. ?>
Copy Code
Open source, mail delivery, Phpmailer
  • 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.