<html> <head> <title>ThaiCreate.Com PHP Sending Email</title> </head> <body> <form action="phpSendMailArrayUploadAttach.php" method="post" enctype="multipart/form-data" name="frmMain"> <table width="343" border="1"> <tr> <td>To</td> <td><input name="txtTo" type="text" ></td> </tr> <tr> <td>Subject</td> <td><input name="txtSubject" type="text"></td> </tr> <tr> <td>Description</td> <td><textarea name="txtDescription" cols="30" rows="4"></textarea></td> </tr> <tr> <td>Form Name</td> <td><input name="txtFormName" type="text"></td> </tr> <tr> <tr> <td>Form Email</td> <td><input name="txtFormEmail" type="text"></td> </tr> <tr> <td>Attachment</td> <td> <input name="fileAttach[]" type="file"><br> <input name="fileAttach[]" type="file"><br> <input name="fileAttach[]" type="file"><br> <input name="fileAttach[]" type="file"><br> <input name="fileAttach[]" type="file"><br> <input name="fileAttach[]" type="file"><br></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com PHP Sending Email</title> </head> <body> <?php $strTo = $_POST["txtTo"]; $strSubject = $_POST["txtSubject"]; $strMessage = nl2br($_POST["txtDescription"]); //*** Uniqid Session ***// $strSid = md5(uniqid(time())); $strHeader = ""; $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"].""; $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"; //*** Attachment ***// for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++) { if($_FILES["fileAttach"]["name"][$i] != "") { $strFilesName = $_FILES["fileAttach"]["name"][$i]; $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i]))); $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; $strHeader .= "Content-Transfer-Encoding: base64\n"; $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n"; $strHeader .= $strContent."\n\n"; } } $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error // if($flgSend) { echo "Email Sending."; } else { echo "Email Can Not Send."; } ?> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท