PHP Send with Attachment Mail sample _php Tutorial

Source: Internet
Author: User
Tags php send mail sendfile
php Send mail, in the Internet will be a lot of related articles, and this article for you to send with attachment mail, do not know the friend can refer to the next

The emailclass.php code is as follows: Subject = $subject; $this->addr_to = $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; The 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-ver Sion: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; The 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: MimeType for "image/gif" $mailfile = new Cmailfile ($subject, $sendto, $replyto, $message, $filename, $mimetype); $mailfile->sendfile (); $subject--Subject $sendto--recipient address $replyto--reply to address $message--Letter content $filename--attachment file name $downfilename--Download the file name $mimetype-- MIME type */?> Demo Copy Code code is as follows: Sendfile ();?>

http://www.bkjia.com/PHPjc/727571.html www.bkjia.com true http://www.bkjia.com/PHPjc/727571.html techarticle php Send mail, in the online will be a lot of related articles, and this article for you to send with attachment mail, do not know the friend can refer to the following emailclass.php code:? class CMai ...

  • Related Article

    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.