<?php if((isset($_POST['submit']))&& $_FILES['attach']['size'] > 0) { $fileatt = $_FILES['attach']; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "test"; // Filename that will be used for the file as the attachment $fileatt_name = $_FILES['attach']['name']; $fileatt_type = $_FILES['attach']['type']; $filesize = $_FILES['attach']['size']; $tmp_filename = $_FILES['attach']['tmp_name']; $email_from = $POST['from']; // Who the email is from $email_subject = "test"; // The Subject of the email $email_txt = "test"; // Message that the email has in it $email_to = $_POST['to']; // Who the email is to $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_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"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { //echo $fileatt; echo "<font face=verdana size=2>The file was successfully sent!</font>"; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } } ?> <form enctype="multipart/form-data" action="attachment.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="attach" type="file" /><br /> TO :<input name="to" type="text" id="to"/><br /> FROM :<input name="from" type="text" id="from"/><br /> <input type="submit" name="submit"value="attach File" /> </form>Code (PHP)
<html> <head> <title>ThaiCreate.Com PHP Sending Email</title> </head> <body> <? $strTo = "[email protected]"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>"; //*** Uniqid Session ***// $strSid = md5(uniqid(time())); $strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<[email protected]>\nReply-To: [email protected]\n"; $strHeader .= "Cc: Mr.Surachai Sirisart<[email protected]>"; $strHeader .= "Bcc: [email protected]"; $strHeader .= "MIME-Version: 1.0\n"; $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n"; $strHeader .= "This is a multi-part message in MIME format.\n"; $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 // $strHeader .= "Content-Transfer-Encoding: 7bit\n\n"; $strHeader .= $strMessage."\n\n"; //*** Files 1 ***// $strFilesName1 = "thaicreate1.txt"; $strContent1 = chunk_split(base64_encode(file_get_contents($strFilesName1))); $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName1."\"\n"; $strHeader .= "Content-Transfer-Encoding: base64\n"; $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName1."\"\n\n"; $strHeader .= $strContent1."\n\n"; //*** Files 2 ***// $strFilesName2 = "thaicreate2.txt"; $strContent2 = chunk_split(base64_encode(file_get_contents($strFilesName2))); $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName2."\"\n"; $strHeader .= "Content-Transfer-Encoding: base64\n"; $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName2."\"\n\n"; $strHeader .= $strContent2."\n\n"; $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error // if($flgSend) { echo "Email Sending."; } else { echo "Email Can Not Send."; } ?> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง