Welcome to the Linux community forum and interact with 2 million technical staff to send emails in php. You can send emails with attachments. 1, emailclass. php? ClassCMailFile {var $ subject; var $ addr_to; var $ text_body; var $ text_encoded; var $ mime_headers; var $ mime_boundary --
Welcome to the Linux community forum, interact with 2 million technical staff> go to php to send an email, and you can send an email with an attachment. 1, emailclass. php? Class CMailFile {var $ subject; var $ addr_to; var $ text_body; var $ text_encoded; var $ mime_headers; var $ mime_boundary = "-- ======
Welcome to the Linux community forum and interact with 2 million technicians>
Php can send emails with attachments.
1. emailclass. php
Class CMailFile {
Var $ subject;
Var $ addr_to;
Var $ text_body;
Var $ text_encoded;
Var $ mime_headers;
Var $ mime_boundary = "-- =========================_ 846811060 == _";
Var $ smtp_headers;
Function CMailFile ($ subject, $ to, $ from, $ msg, $ filename, $ downfilename, $ mimetype = "application/octet-stream", $ mime_filename = false ){
$ This-> subject = $ subject;
$ This-> addr_to = $;
$ This-> smtp_headers = $ this-> write_smtpheaders ($ from );
$ This-> text_body = $ this-> write_body ($ msg );
$ This-> text_encoded = $ this-> attach_file ($ filename, $ downfilename, $ mimetype, $ mime_filename );
$ This-> mime_headers = $ this-> write_mimeheaders ($ filename, $ mime_filename );
}
Function attach_file ($ filename, $ downfilename, $ mimetype, $ mime_filename ){
$ Encoded = $ this-> encode_file ($ filename );
If ($ mime_filename) $ filename = $ mime_filename;
$ Out = "--". $ this-> mime_boundary. "\ n ";
$ Out = $ out. "Content-type:". $ mimetype. "; name = \" $ filename \ "; \ n ";
$ Out = $ out. "Content-Transfer-Encoding: base64 \ n ";
$ Out = $ out. "Content-disposition: attachment; filename = \" $ downfilename \ "\ n ";
$ Out = $ out. $ encoded. "\ n ";
$ Out = $ out. "--". $ this-> mime_boundary. "--". "\ n ";
Return $ out;
}
Function encode_file ($ sourcefile ){
If (is_readable ($ sourcefile )){
$ Fd = fopen ($ sourcefile, "r ");
$ Contents = fread ($ fd, filesize ($ sourcefile ));
$ Encoded = chunk_split (base64_encode ($ contents ));
Fclose ($ fd );
}
Return $ encoded;
}
Function sendfile (){
$ Headers = $ this-> smtp_headers. $ this-> mime_headers;
$ Message = $ this-> text_body. $ this-> text_encoded;
Mail ($ this-> addr_to, $ this-> subject, $ message, $ 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;
}
[1] [2]