PHP simple implementation of sending mail with attachments, PHP send attachment mail _php tutorial

Source: Internet
Author: User

PHP simple implementation of sending messages with attachments, PHP send attachment mail


The example in this article describes the simple implementation of PHP to send the message with attachments. Share to everyone for your reference. Specific as follows:

Here is the static HTML code:

  Send mail with Attachments       

sendmail.php File Code:

<?php//Get form information $from = $_post[' from '];  $to = $_post[' to '];  $subject = $_post[' subject ');  $body = $_post[' body ']; Define the dividing line $boundary = "345894369383"; The dividing line is a string of irregular characters//set header $header = "content-type:multipart/mixed;  boundary= $boundary/r/n ";  $header. = "From: $from/r/n";  Get the file content of the uploaded file $file = $_files[' upload_file ' [' tmp_name '];  Determine the MIME type of the uploaded file $mimeType = $_files[' upload_file ' [' type '];  Get the file name of the upload $fileName = $_files[' upload_file ' [' name ']; Read Upload file $fp = fopen ($file, "R"); Open File $read = fread ($fp, FileSize ($file)); Read in File $read = Base64_encode ($read); Base64 Encoding $read = Chunk_split ($read); Cut string//Set up the main body of the message, divided into the contents of the message and the contents of two parts $body = "-$boundary content-type:text/plain; Charset=iso-8859-1 content-transfer-encoding:8bit $body--$boundary content-type: $mimeType; Name= $fileName content-disposition:attachment;  Filename= $fileName content-transfer-encoding:base64 $read--$boundary--"; Sends the message and outputs whether or not to send the successful message if (Mail ($to, $subject, $body, $header)) {echo "Letter sent as";  } else {echo "message failed to send"; }?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1014426.html www.bkjia.com true http://www.bkjia.com/PHPjc/1014426.html techarticle PHP Simple implementation of sending messages with attachments, PHP send attachments email examples of PHP simple implementation of the message sent with attachments. Share to everyone for your reference. Specific as follows: The following ...

  • 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.