Example of sending an email with attachments using PHPMailer
- /**
- * PHPMailer email sending
- * Edit bbs.it-home.org
- */
- Require_once ('include/PHPMailer/class. phpmailer. php'); // import the PHPMAILER class
- $ Mail = new PHPMailer (); // Create an instance
- $ Mail-> CharSet = 'utf-8'; // sets the character set.
- $ Mail-> SetLanguage ('ch', 'include/PHPMailer/language/'); // sets the Directory of the language type and language file
- $ Mail-> IsSMTP (); // send using SMTP
- $ Mail-> SMTPAuth = true; // Sets whether the server requires SMTP Authentication.
- $ Mail-> Host = SMTP_SERVER; // SMTP Host address
- $ Mail-> Port = SMTP_SERVER_PORT; // SMTP host Port
- $ Mail-> From = SMTP_USER_MAIL; // The sender's EMAIL address.
- $ Mail-> FromName = 'jasonxu '; // The user name of the sender in the SMTP host
- $ Mail-> Username = SMTP_USER_NAME; // sender's name
- $ Mail-> Password = SMTP_USER_PASS; // The sender's Password on the SMTP host
- $ Mail-> Subject = 'Test mail title'; // mail Subject
- $ Mail-> AltBody = 'text/html '; // sets the alternate display when the email body does not support HTML.
- $ Mail-> Body = 'Test mail content'; // Make the mail content
- $ Mail-> IsHTML (true); // whether it is an HTML email
- $ Mail-> AddAddress ('chinajason2008 # gmail.com ', 'jasonxu'); // recipient's address and name
- $ Mail-> AddReplyTo ('chinajason2008 # gmail.com ', 'jasonxu'); // address and name replied to by the recipient
- $ Mail-> AddAttachment ('include/id.csv', 'att.csv '); // The path and name of the attachment
- If (! $ Mail-> Send () // Send an email
- Var_dump ($ mail-> ErrorInfo); // view the error message sent
- ?>
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 |