Php simply sends emails with attachments, and php sends attachments
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:
<Html>
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.