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