หัวข้อ: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 19 เมษายน 2017, 17:32:15
<html> <head> <title>ThaiCreate.Com PHP Sending Email</title> </head> <body> <? $strTo = "is_php@hotmail.com"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>";
//*** Uniqid Session ***// $strSid = md5(uniqid(time()));
$strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<webmaster@thaicreate.com>\nReply-To: webmaster@thaicreate.com\n"; $strHeader .= "Cc: Mr.Surachai Sirisart<surachai@thaicreate.com>"; $strHeader .= "Bcc: webmaster@thaicreate.com";
$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 Files ***// $arrFiles[] = "thaicreate1.txt"; $arrFiles[] = "thaicreate2.txt"; $arrFiles[] = "thaicreate3.txt"; $arrFiles[] = "thaicreate4.txt"; $arrFiles[] = "thaicreate5.txt";
for($i=0;$i<count($arrFiles);$i++) { if(trim($arrFiles[$i]) != "") { $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName)));
$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>
ทำยังไงให้อัพไฟล์ตรงสีแดงได้ครับ
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: zang11015 ที่ 20 เมษายน 2017, 01:34:38
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 20 เมษายน 2017, 13:06:32
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
แล้วถ้า กดอัพโหลดรูป เพิ่มโค๊ดอย่างไรเหรอครับ :wanwan017:
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: zang11015 ที่ 20 เมษายน 2017, 21:06:07
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
แล้วถ้า กดอัพโหลดรูป เพิ่มโค๊ดอย่างไรเหรอครับ :wanwan017: <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <? $strTo = "is_php@hotmail.com"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>";
//*** Uniqid Session ***// $strSid = md5(uniqid(time()));
$strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<webmaster@thaicreate.com>\nReply-To: webmaster@thaicreate.com\n"; //$strHeader .= "Cc: Mr.Surachai Sirisart<surachai@thaicreate.com>"; //$strHeader .= "Bcc: webmaster@thaicreate.com";
$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 Files ***// //$arrFiles[] = $_FILES['my_file']['name'];
foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++) { if(trim($arrFiles[$i]) != "") { $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName)));
$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."; } ?>
แบบง่ายๆครับ
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 21 เมษายน 2017, 19:09:37
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
แล้วถ้า กดอัพโหลดรูป เพิ่มโค๊ดอย่างไรเหรอครับ :wanwan017: <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <? $strTo = "is_php@hotmail.com"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>";
//*** Uniqid Session ***// $strSid = md5(uniqid(time()));
$strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<webmaster@thaicreate.com>\nReply-To: webmaster@thaicreate.com\n"; //$strHeader .= "Cc: Mr.Surachai Sirisart<surachai@thaicreate.com>"; //$strHeader .= "Bcc: webmaster@thaicreate.com";
$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 Files ***// //$arrFiles[] = $_FILES['my_file']['name'];
foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++) { if(trim($arrFiles[$i]) != "") { $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName)));
$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."; } ?>
แบบง่ายๆครับ ส่งไปเเล้ว ไฟล์ที่เข้าเมล์เป็น 0 Byte ครับ แก้อย่างไรเหรอครับ :P
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: zang11015 ที่ 23 เมษายน 2017, 02:57:32
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
แล้วถ้า กดอัพโหลดรูป เพิ่มโค๊ดอย่างไรเหรอครับ :wanwan017: <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <? $strTo = "is_php@hotmail.com"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>";
//*** Uniqid Session ***// $strSid = md5(uniqid(time()));
$strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<webmaster@thaicreate.com>\nReply-To: webmaster@thaicreate.com\n"; //$strHeader .= "Cc: Mr.Surachai Sirisart<surachai@thaicreate.com>"; //$strHeader .= "Bcc: webmaster@thaicreate.com";
$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 Files ***// //$arrFiles[] = $_FILES['my_file']['name'];
foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++) { if(trim($arrFiles[$i]) != "") { $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName)));
$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."; } ?>
แบบง่ายๆครับ ส่งไปเเล้ว ไฟล์ที่เข้าเมล์เป็น 0 Byte ครับ แก้อย่างไรเหรอครับ :P <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php
foreach ($_FILES["my_file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["my_file"]["tmp_name"][$key]; $name = basename($_FILES["my_file"]["name"][$key]); move_uploaded_file($tmp_name, $name); } }
$to = "somebodyelse@example.com"; $subject = "HTML email"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time());
$headers = 'From: <webmaster@example.com>'.$eol; $headers .= 'Cc: myboss@example.com'.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"".$eol.$eol; $message = "This is a multi-part message in MIME format.".$eol; $message .= "--".$strSid.$eol; $message .= "Content-type: text/html; charset=UTF-8".$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= $messages.$eol.$eol;
if($_FILES['my_file'] != ""){ foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++){ if(trim($arrFiles[$i]) != ""){ $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName))); $message .= "--".$strSid.$eol; $message .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"".$eol.$eol; $message .= $strContent.$eol.$eol; } }
$message .= "--".$strSid."--".$eol;
$ss = @mail($to,$subject,$message,$headers);
} ?>
ปรับ permission โฟเดอร์เก็บรูปหรือไฟล์เป็น 777 ด้วยนะครับ :wanwan004: :wanwan004: :wanwan004: :wanwan004:
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 23 เมษายน 2017, 22:33:35
ตรงสีแดงแก้เป็นชื่อรูปครับ เอารูปไปเก็บไว้โฟเดอร์เดียวกับไฟล์
แล้วถ้า กดอัพโหลดรูป เพิ่มโค๊ดอย่างไรเหรอครับ :wanwan017: <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <? $strTo = "is_php@hotmail.com"; $strSubject = "Test Send Mail"; $strMessage = "My Body & <b>My Description</b>";
//*** Uniqid Session ***// $strSid = md5(uniqid(time()));
$strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<webmaster@thaicreate.com>\nReply-To: webmaster@thaicreate.com\n"; //$strHeader .= "Cc: Mr.Surachai Sirisart<surachai@thaicreate.com>"; //$strHeader .= "Bcc: webmaster@thaicreate.com";
$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 Files ***// //$arrFiles[] = $_FILES['my_file']['name'];
foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++) { if(trim($arrFiles[$i]) != "") { $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName)));
$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."; } ?>
แบบง่ายๆครับ ส่งไปเเล้ว ไฟล์ที่เข้าเมล์เป็น 0 Byte ครับ แก้อย่างไรเหรอครับ :P <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php
foreach ($_FILES["my_file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["my_file"]["tmp_name"][$key]; $name = basename($_FILES["my_file"]["name"][$key]); move_uploaded_file($tmp_name, $name); } }
$to = "somebodyelse@example.com"; $subject = "HTML email"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time());
$headers = 'From: <webmaster@example.com>'.$eol; $headers .= 'Cc: myboss@example.com'.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"".$eol.$eol; $message = "This is a multi-part message in MIME format.".$eol; $message .= "--".$strSid.$eol; $message .= "Content-type: text/html; charset=UTF-8".$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= $messages.$eol.$eol;
if($_FILES['my_file'] != ""){ foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++){ if(trim($arrFiles[$i]) != ""){ $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName))); $message .= "--".$strSid.$eol; $message .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"".$eol.$eol; $message .= $strContent.$eol.$eol; } }
$message .= "--".$strSid."--".$eol;
$ss = @mail($to,$subject,$message,$headers);
} ?>
ปรับ permission โฟเดอร์เก็บรูปหรือไฟล์เป็น 777 ด้วยนะครับ :wanwan004: :wanwan004: :wanwan004: :wanwan004: ลองอันล่าสุดแล้ว ส่งได้หลายไฟล์ แต่ เข้าเมล์แล้วยังเป็น 0 อ่ะ :P :P
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 06 พฤศจิกายน 2017, 20:24:11
โค๊ดล่าสุดของ ท่าน zang11015 ลองใช้แล้วใช้ได้เลย แต่ มันจะอัพไฟล์ เข้าโฟลเดอร์ ในเซิฟเว่อร์เราด้วย ซึ่งน่าจะอันตรายเผื่อใครอัพไวรัสเข้ามา มีวิธีทำให้ไม่ต้องอัพเข้า server ไหมครับ ให้มันส่งไปที่เมล์อย่างเดียว :P <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php
foreach ($_FILES["my_file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["my_file"]["tmp_name"][$key]; $name = basename($_FILES["my_file"]["name"][$key]); move_uploaded_file($tmp_name, $name); } }
$to = "somebodyelse@example.com"; $subject = "HTML email"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time());
$headers = 'From: <webmaster@example.com>'.$eol; $headers .= 'Cc: myboss@example.com'.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"".$eol.$eol; $message = "This is a multi-part message in MIME format.".$eol; $message .= "--".$strSid.$eol; $message .= "Content-type: text/html; charset=UTF-8".$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= $messages.$eol.$eol;
if($_FILES['my_file'] != ""){ foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++){ if(trim($arrFiles[$i]) != ""){ $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName))); $message .= "--".$strSid.$eol; $message .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"".$eol.$eol; $message .= $strContent.$eol.$eol; } }
$message .= "--".$strSid."--".$eol;
$ss = @mail($to,$subject,$message,$headers);
} ?>
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: esanza.com ที่ 06 พฤศจิกายน 2017, 20:31:49
โค๊ดล่าสุดของ ท่าน zang11015 ลองใช้แล้วใช้ได้เลย แต่ มันจะอัพไฟล์ เข้าโฟลเดอร์ ในเซิฟเว่อร์เราด้วย ซึ่งน่าจะอันตรายเผื่อใครอัพไวรัสเข้ามา มีวิธีทำให้ไม่ต้องอัพเข้า server ไหมครับ ให้มันส่งไปที่เมล์อย่างเดียว :P <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php
foreach ($_FILES["my_file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["my_file"]["tmp_name"][$key]; $name = basename($_FILES["my_file"]["name"][$key]); move_uploaded_file($tmp_name, $name); } }
$to = "somebodyelse@example.com"; $subject = "HTML email"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time());
$headers = 'From: <webmaster@example.com>'.$eol; $headers .= 'Cc: myboss@example.com'.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"".$eol.$eol; $message = "This is a multi-part message in MIME format.".$eol; $message .= "--".$strSid.$eol; $message .= "Content-type: text/html; charset=UTF-8".$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= $messages.$eol.$eol;
if($_FILES['my_file'] != ""){ foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++){ if(trim($arrFiles[$i]) != ""){ $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName))); $message .= "--".$strSid.$eol; $message .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"".$eol.$eol; $message .= $strContent.$eol.$eol; } }
$message .= "--".$strSid."--".$eol;
$ss = @mail($to,$subject,$message,$headers);
} ?> ตามหลักโปรแกรมมิ่งมันก็ต้องอัพขึ้น server เราก่อนนะคับ ไม่งั้นเราจะส่งไปที่ปลายทางยังไง งง?
หัวข้อ: Re: php ส่งได้หลายรูปไป อีเมล์ เราจะอัพรูปเข้าไปแก้อย่างไรเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 07 พฤศจิกายน 2017, 08:54:15
โค๊ดล่าสุดของ ท่าน zang11015 ลองใช้แล้วใช้ได้เลย แต่ มันจะอัพไฟล์ เข้าโฟลเดอร์ ในเซิฟเว่อร์เราด้วย ซึ่งน่าจะอันตรายเผื่อใครอัพไวรัสเข้ามา มีวิธีทำให้ไม่ต้องอัพเข้า server ไหมครับ ให้มันส่งไปที่เมล์อย่างเดียว :P <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php
foreach ($_FILES["my_file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["my_file"]["tmp_name"][$key]; $name = basename($_FILES["my_file"]["name"][$key]); move_uploaded_file($tmp_name, $name); } }
$to = "somebodyelse@example.com"; $subject = "HTML email"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time());
$headers = 'From: <webmaster@example.com>'.$eol; $headers .= 'Cc: myboss@example.com'.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"".$eol.$eol; $message = "This is a multi-part message in MIME format.".$eol; $message .= "--".$strSid.$eol; $message .= "Content-type: text/html; charset=UTF-8".$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= $messages.$eol.$eol;
if($_FILES['my_file'] != ""){ foreach ($_FILES['my_file']['name'] as $file) { $arrFiles[] = $file; }
for($i=0;$i<count($arrFiles);$i++){ if(trim($arrFiles[$i]) != ""){ $strFilesName = $arrFiles[$i]; $strContent = chunk_split(base64_encode(file_get_contents($strFilesName))); $message .= "--".$strSid.$eol; $message .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"".$eol.$eol; $message .= $strContent.$eol.$eol; } }
$message .= "--".$strSid."--".$eol;
$ss = @mail($to,$subject,$message,$headers);
} ?> ตามหลักโปรแกรมมิ่งมันก็ต้องอัพขึ้น server เราก่อนนะคับ ไม่งั้นเราจะส่งไปที่ปลายทางยังไง งง? เป็นฟอร์มเมล์ เหมือน contact form ครับ แค่เราแนบไฟล์เข้าไป มันจะส่งไปที่เมล์ปลายทางเรยครับ :wanwan019:
|