Example of sending an email with attachments in php
Source: Internet
Author: User
Php sends emails. many related articles will be posted online. This article describes sending emails with attachments. if you do not know, refer to emailclass. php.
The code is as follows:
Class CMailFile {
Var $ subject;
Var $ addr_to;
Var $ text_body;
Var $ text_encoded;
Var $ mime_headers;
Var $ mime_boundary = "-- =========================_ 846811060 == _";
Var $ smtp_headers;
Function write_body ($ msgtext ){
$ Out = "--". $ this-> mime_boundary. "\ n ";
$ Out = $ out. "Content-Type: text/plain; charset = \" us-ascii \ "\ n ";
$ Out = $ out. $ msgtext. "\ n ";
Return $ out;
}
Function write_mimeheaders ($ filename, $ mime_filename ){
If ($ mime_filename) $ filename = $ mime_filename;
$ Out = "MIME-version: 1.0 \ n ";
$ Out = $ out. "Content-type: multipart/mixed ;";
$ Out = $ out. "boundary = \" $ this-> mime_boundary \ "\ n ";
$ Out = $ out. "Content-transfer-encoding: 7BIT \ n ";
$ Out = $ out. "X-attachments: $ filename; \ n ";
Return $ out;
}
Function write_smtpheaders ($ addr_from ){
$ Out = "From: $ addr_from \ n ";
$ Out = $ out. "Reply-To: $ addr_from \ n ";
$ Out = $ out. "X-Mailer: PHP3 \ n ";
$ Out = $ out. "X-Sender: $ addr_from \ n ";
Return $ out;
}
}
/* Usage-for example, if mimetype is "image/gif"
$ Mailfile = new CMailFile ($ subject, $ sendto, $ replyto, $ message, $ filename, $ mimetype );
$ Mailfile-> sendfile ();
$ Subject -- topic
$ Sendto -- recipient address
$ Replyto -- Reply address
$ Message -- Mail content
$ Filename -- attachment file name
$ Downfilename -- Name of the file in the lower region
$ Mimetype -- mime type
*/
?>
Demo
The code is as follows:
Require_once ('emailclass. php ');
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