Php simply sends emails with attachments, and php sends attachments _ PHP Tutorial

Source: Internet
Author: User
Php simply sends emails with attachments, and php sends attachments. Php simply sends emails with attachments. php sends attachments. this example describes how php simply sends emails with attachments. Share it with you for your reference. The following describes how to send an email with an attachment in php and an email with an attachment in php.

This example describes how php can send emails with attachments. Share it with you for your reference. The details are as follows:

The static html code is as follows:

  Emails with attachments       

Sendmail. php file code:

<? Php // Obtain the form information $ from =$ _ POST ['from']; $ to =$ _ POST ['to']; $ subject = $ _ POST ['subobject']; $ body = $ _ POST ['body']; // defines the boundary $ boundary = "345894369383 "; // the demarcation 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 content of the uploaded file $ file =$ _ FILES ['upload _ file'] ['tmp _ name']; // Determine the MIME type of the uploaded file $ mimeType = $ _ FILES ['upload _ file'] ['type']; // Obtain the file name. $ FileName = $ _ FILES ['upload _ file'] ['name']; // read the uploaded file $ fp = fopen ($ file, "r "); // open the file $ read = fread ($ fp, filesize ($ file); // read the file $ read = base64_encode ($ read ); // base64 encoded $ read = chunk_split ($ read); // cut the string // create the subject of the email, divided into two parts: Mail Content and attachment Content $ body = "-- $ boundary Content-type: text/plain; charset = ISO-8859-1 Content-transfer-encoding: 8bit $ body -- $ boundary Content-type: $ mimeType; name = $ fileName Content-disp Osition: attachment; filename = $ fileName Content-transfer-encoding: base64 $ read -- $ boundary --"; // send the email and output the message if (mail ($ to, $ subject, $ body, $ header) {echo "mail sent successfully ";} else {echo "email sending failed" ;}?>

I hope this article will help you with php programming.

The example in this article describes how php simply sends emails with attachments. Share it with you for your reference. The details are as follows...

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.