Simple PHP form: Attachment to email (code golf) -


Imagine a user who would like to put a form on their website, which is a website visitor to upload a file and a simple The message, which will be emailed immediately (i.e., the file is not stored on the server, or if it is only temporarily) in the message body as a file attachment with the note.

See more information

What is the easiest way to accomplish this?

In simple words:

  • Size (code golf)
  • Not ambiguous for ambiguity (for size Limitations are fine) Easy to implement (ideally all in one file, no external source)
  • Self-Examples (if displayed without a form post, this form displays) < / Li>

It is almost reverse:. It could have been almost answered, but it does not really show the code.

Just for fun, I thought I would knock it. I thought I fully understand I was not able to know how the border works, it was very complex, after all I did the work that the beginning and the closing '-' were important and it was closed.

  & lt ;? Php if (isset ($ _ POST ['submit'])) {// the form has been submitted, a good thank you message for the message $ output = '& lt; H1 & gt; Thanks for your file and message! & Lt; / H1> '; // Do not display any form flag (cheap way!) $ Flags = 'style = "display: none;"'; // Deal with Email - = 'me@example.com'; $ Theme = 'a file for you'; $ Message = tab_tag ($ _ POST ['message']); $ Attachment = chunk_split (base64_axx (file_gate_content ($ _ files ['file'] ['tmp_name']))); $ Filename = $ _FILES ['file'] ['name']; $ Range = MD5 (date ('r', time ())); $ Headers = "From: webmaster@example.com \ r \ n Reply-To: webmaster@example.com"; $ Headers = "\ R \ nmm-version: 1.0 \ r \ nContentType: multipart / mixed; border = \" _ 1_ $ border \ ""; $ Message = "This MIME format contains multi-part message. --_ 1_ $ border content-type: multiple / optional; boundary = \" _ 2_ $ range \ "--_2_ $ range content-type: text / Plain; charset = \ "ISO-885 9-1 \" content-transfer-encoding: $ 7bit message --_2_ $ limit - - $ 1 limit content-type: application / octet-stream; name = \ "$ filename \ "Content-Transfer-Encoding: base64 Content-Repository: Attachment $ Attachment --_ 1_ $ Limit -"; Mail ($ $ $ $ theme, $ message, $ headers); }? & Gt; & Lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // N" "http://www.w3.org/TR/html4/strict.dtd"> & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" & gt; & Lt; Title & gt; MailFile & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php $ output echo; ? & Gt; & Lt; Form enctype = "multipart / form-data" action = "& lt ;? Php echo $ _SERVER ['PHP_SELF'] ;? & gt;" Method = "post" & lt ;? Php echo $ flags ;? & Gt; & Gt; & Lt; P & gt; & Lt; Label = "message" & gt; Message & lt; / Label & gt; & Lt; Textarea name = "message" id = "message" cols = "20" lines = "8" & gt; & Lt; / Textarea & gt; & Lt; / P & gt; For file & lt; P & gt; & Lt; Label = "file" & gt; File & lt; / Label & gt; & Lt; Input type = "file" name = "file" id = "file" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" name = "submit" id = "submit" value = "send" & gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Inline CSS is a bit cheaper to hide the form really, and clearly to hide the form, and you almost certainly want a little bit more response to the user! Apart from this, I'm probably working to get the file's actual content-type fraud and application / octet-stream instead of spending a little more time, but that part is very interesting.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -