Example of sending emails with attachments using PHPMailer

WBOY
Release: 2016-07-25 08:59:42
Original
877 people have browsed it
  1. /**
  2. * PHPMailer email sending
  3. * Edit bbs.it-home.org
  4. */
  5. require_once('include/PHPMailer/class.phpmailer.php'); //Import PHPMAILER class
  6. $mail = new PHPMailer(); // Create an instance
  7. $mail -> CharSet='utf-8'; //Set the character set
  8. $mail -> SetLanguage('ch','include/PHPMailer/language/'); //Set the language type and language The directory where the file is located
  9. $mail -> IsSMTP(); //Use SMTP to send
  10. $mail -> SMTPAuth = true; //Set 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; //Sender's EMAIL address
  14. $mail -> FromName = 'jasonxu'; //Send The sender’s username in the SMTP host
  15. $mail -> Username = SMTP_USER_NAME; //The sender’s name
  16. $mail -> Password = SMTP_USER_PASS; //The sender’s password in the SMTP host
  17. $mail -> Subject = 'Test email title'; //Email subject
  18. $mail -> AltBody = 'text/html'; //Set the backup display when the email body does not support HTML
  19. $mail -> Body = 'Test the content of the email'; //The email content is made
  20. $mail -> IsHTML(true); //Is it an HTML email
  21. $mail -> AddAddress('chinajason2008#gmail.com','jasonxu' ); //The address and name of the recipient
  22. $mail -> AddReplyTo('chinajason2008#gmail.com','jasonxu'); //The address and name of the recipient when replying
  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. ?>
Copy code

Note: When phpmailer adds an attachment, the suffix of the attachment must be written in the name of the attachment. If not, the suffix of the attachment must be written. , the default attachment suffix will be .txt. For example $mail -> AddAttachment('include/id.csv','att');//The path and name of the attachment If you add an attachment and send it as above, the final attachment you receive may be att.txt. AddAttachment can set the attachment encoding method and attachment type. For example, the above attachment addition can also be set to $mail -> AddAttachment('include/id.csv','att.csv',"binary","text/comma-separated-values");//The path and name of the attachment, There are several encoding methods for attachments: 8bit, base64, binary, and quoted-printable encoding are supported

The MIME Type accepted by CSV · application/octet-stream · text/comma-separated-values ​​(recommended) · text/csv Therefore, the attachment type of the csv format file can be any of the above three types. 1 2 Next Page Last Page



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template