Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a combination of multiple scripts and a bit of reading. I haven't added any form processing or the like, but it allows for the use of the option to attach multiple files through one input button. Hope its helpful to someone. I'm sure it breaks all kinds of standards. I do know it works in Chrome 31 and IE10.</p> <p>Edit: Working with this little script, I added HTML formatting for the message and the thank you message replacement.</p> <pre><code>&lt;?php if(isset($_POST['Submit'])) { $email_to = ""; $email_subject = ""; $thankyou = "thanks.html"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; function died($error) { echo "Sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;"; echo $error."&lt;br /&gt;&lt;br /&gt;"; echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;"; die(); } $requester_name = $_POST['requester_name']; // required $requester_email = $_POST['requester_email']; // required function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message = "&lt;html&gt;&lt;body&gt; \r\n"; $email_message .= "&lt;table style=\"border: 1px #777 solid; font-family: Arial; font-size: 13px;\" cellpadding=\"7\"&gt; \r\n"; $email_message .= "&lt;tr&gt;&lt;td style=\"background: #444; color:#fff;\"&gt;&lt;strong&gt;New Hire Form&lt;/strong&gt;&lt;/td&gt;&lt;td style=\"background: #444; color:#fff;\"&gt;Requirements&lt;/td&gt;&lt;/tr&gt;" . "\n"; $email_message .= "&lt;tr&gt;&lt;td style=\"background: #ccc;\"&gt;&lt;strong&gt;Requester Name: &lt;/strong&gt;&lt;/td&gt;&lt;td style=\"background: #ddd;\"&gt;" .clean_string($requester_name). "&lt;/td&gt;&lt;/tr&gt;" . "\n"; $email_message .= "&lt;tr&gt;&lt;td style=\"background: #ccc;\"&gt;&lt;strong&gt;Requester Email: &lt;/strong&gt;&lt;/td&gt;&lt;td style=\"background: #ddd;\"&gt;".clean_string($requester_email). "&lt;/td&gt;&lt;/tr&gt;" . "\n"; $email_message .= "&lt;/table&gt; \r\n"; $email_message .= "&lt;/body&gt;&lt;/html&gt;"; // multipart boundary $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; for($i=0;$i&lt;count($_FILES['attachfile']['name']);$i++) { if($_FILES['attachfile']['name'][$i] != "") { //here you will get all files selected by user. $name = ($_FILES['attachfile']['name'][$i]); $tmp_name = ($_FILES['attachfile']['tmp_name'][$i]); $type = ($_FILES['attachfile']['type'][$i]); $size = ($_FILES['attachfile']['size'][$i]); echo count($_Files['attachfile']) ; echo $_FILES['attachfile']['name'][$i] ; echo $_FILES['attachfile']['tmp_name'][$i] ; echo $_FILES['attachfile']['type'][$i] ; // Read the file content into a variable $file = fopen($tmp_name,'rb'); $data = fread($file,filesize($tmp_name)); // Close the file fclose($file); $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } } $headers .= 'From: '.$email_sender."\r\n". // Mail will be sent from your Admin ID 'Reply-To: '.$Email."\r\n" . // Reply to Sender Email 'X-Mailer: PHP/' . phpversion(); // headers for attachment $headers .= "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; @mail($email_to, $email_subject, $email_message, $headers); ?&gt; &lt;script&gt;location.replace('&lt;?php echo $thankyou;?&gt;')&lt;/script&gt; &lt;?php } die(); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload