Example of sending an email with attachments using PHPMailer

Source: Internet
Author: User
Example of sending an email with attachments using PHPMailer

  1. /**
  2. * PHPMailer email sending
  3. * Edit bbs.it-home.org
  4. */
  5. Require_once ('include/PHPMailer/class. phpmailer. php'); // import the PHPMAILER class
  6. $ Mail = new PHPMailer (); // Create an instance
  7. $ Mail-> CharSet = 'utf-8'; // sets the character set.
  8. $ Mail-> SetLanguage ('ch', 'include/PHPMailer/language/'); // sets the Directory of the language type and language file
  9. $ Mail-> IsSMTP (); // send using SMTP
  10. $ Mail-> SMTPAuth = true; // Sets whether the server requires SMTP Authentication.
  11. $ Mail-> Host = SMTP_SERVER; // SMTP Host address
  12. $ Mail-> Port = SMTP_SERVER_PORT; // SMTP host Port
  13. $ Mail-> From = SMTP_USER_MAIL; // The sender's EMAIL address.
  14. $ Mail-> FromName = 'jasonxu '; // The user name of the sender in the SMTP host
  15. $ Mail-> Username = SMTP_USER_NAME; // sender's name
  16. $ Mail-> Password = SMTP_USER_PASS; // The sender's Password on the SMTP host
  17. $ Mail-> Subject = 'Test mail title'; // mail Subject
  18. $ Mail-> AltBody = 'text/html '; // sets the alternate display when the email body does not support HTML.
  19. $ Mail-> Body = 'Test mail content'; // Make the mail content
  20. $ Mail-> IsHTML (true); // whether it is an HTML email
  21. $ Mail-> AddAddress ('chinajason2008 # gmail.com ', 'jasonxu'); // recipient's address and name
  22. $ Mail-> AddReplyTo ('chinajason2008 # gmail.com ', 'jasonxu'); // address and name replied to by the recipient
  23. $ Mail-> AddAttachment ('include/id.csv', 'att.csv '); // The path and name of the attachment
  24. If (! $ Mail-> Send () // Send an email
  25. Var_dump ($ mail-> ErrorInfo); // view the error message sent
  26. ?>

Note: accept. For example, $ mail-> AddAttachment ('include/id.csv ', 'Att'); // The Attachment and its name indicate that if the attachment is sent to a similar attachment, the final attachment can be att.txt. AddAttachment can be used to set the attachment encoding method and attachment type. for example, the attachment can also be set to $ mail-> AddAttachment ('include/id.csv', 'att.csv ', "binary ", "text/comma-separated-values"); // The path and name of the attachment, and the encoding method of the attachment are as follows: 8 bit, base64, binary, and quoted-printable encoding

While CSV accepts MIME Type · application/octet-stream · text/comma-separated-values (recommended) · text/csv, the attachment type of csv files can be any of the above three types.12. Next page

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.