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