หัวข้อ: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: Fallen ที่ 16 ตุลาคม 2017, 19:10:35
<form method="post" enctype="multipart/form-data"> <input type='file' name='file[]' multiple='multiple' /> <input type="submit" value="Upload"> </form> <?php $to = "email@xxx.com"; $subject = "หัวข้อ"; $eol = PHP_EOL; $messages = "test"; $strSid = md5(time()); $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;
for($i=0;$i<count($_FILES['file']['name']);$i++){ if($_FILES["file"]["name"][$i]!= ""){ $strFilesName = $_FILES["file"]["name"][$i]; $strContent = chunk_split(base64_encode(file_get_contents($_FILES["file"]["tmp_name"][$i]))); $headers .= "--".$strSid."\n"; $headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; $headers .= "Content-Transfer-Encoding: base64\n"; $headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n"; $headers .= $strContent."\n\n"; } } $message .= "--".$strSid."--".$eol; $ss = @mail($to,$subject,$message,$headers);
?>
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: imaim09 ที่ 01 พฤศจิกายน 2017, 17:01:57
:wanwan013: :wanwan013:
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: dermapond ที่ 01 พฤศจิกายน 2017, 17:56:19
ไม่มี error log แสดงหรอครับ
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: Fallen ที่ 06 พฤศจิกายน 2017, 20:03:07
ไม่มี error log แสดงหรอครับ
กดปุ๊ปข้อความส่งทันที ไม่มี error เลยครับ ผมมาลองทดสอบอีกที เหมือนว่า โค๊ดไฟล์แนบมันไม่เกียวอะไรกับ โค๊ดทั้งหมดนี้เลย :wanwan001:
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: infamous ที่ 06 พฤศจิกายน 2017, 21:29:38
โค๊ดนี้เหมือนเคยเห็นที่ไหน thaicreate เจ้าเก่า?
ผมไม่แน่ใจว่า skill ของท่านมีขนาดไหน ถ้าไม่อยากปวดหัวกับการส่งเมล์ ลองหา library มาใช้งานดูครับ
เช่น พวก PHPMailer : https://github.com/PHPMailer/PHPMailer
ผมลองเอามาเสียบให้ระบบ ถือว่าทำงานได้ดีเลยทีเดียว ยืดหยุ่นพอสมควรครับ
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: Fallen ที่ 07 พฤศจิกายน 2017, 08:57:35
โค๊ดนี้เหมือนเคยเห็นที่ไหน thaicreate เจ้าเก่า?
ผมไม่แน่ใจว่า skill ของท่านมีขนาดไหน ถ้าไม่อยากปวดหัวกับการส่งเมล์ ลองหา library มาใช้งานดูครับ
เช่น พวก PHPMailer : https://github.com/PHPMailer/PHPMailer
ผมลองเอามาเสียบให้ระบบ ถือว่าทำงานได้ดีเลยทีเดียว ยืดหยุ่นพอสมควรครับ
สกิลระดับเริ่มต้นครับ เอามาจากนั้นเเหละครับ อิอิอิ พวก library ผมไม่เคยทำเลย เพราะต้อง include อะไรเข้าไป ไม่รุ้ว่าดีกว่า code แนวที่ผมถามยังไงครับ? หรือ ว่ามันเสถียรกว่า และ มีการพัฒนา
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: f206cs ที่ 07 ธันวาคม 2017, 09:43:21
ถ้าใช้พวก phpMailer มันง่ายกว่าไงครับ และรองรับการใช้งานได้หลากหลายกว่า อาจจะยุ่งตอนเริ่มต้น แลัตอน set ค่าบางอย่าง แต่ถ้าเริ่มได้แล้วที่เหลือง่ายมากครับ ส่วนเรื่องส่งเมลล์แนบไฟล์ด้วย function mail ของ php เอาตัวอย่างของผมไปศึกษาดูครับ **ผมข้ามหน้า form ไปนะครับ เป็นตัวที่ผมทำให้ลูกค้า เอามาแบ่งปันครับ** **ในหน้า form ส่งเมลล์ ส่วนของไฟล์ จะให้เลือกได้ว่าจะเอาไฟล์อะไรส่งไปบ้าง (code มันเลยยุ่งๆหน่อย)** <? $detail = " <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-874\"> <title>".$SubJect."</title> </head> <body>".$MailDetail."</body> </html> ";
$email_from = $SendFrom; // Who the email is from $email_subject = $subject; // The Subject of the email $email_message = $detail;// Message that the email has in it $email_to = $SendTo; // Who the email is too
$headers = "From: ".$email_from; if(trim($SendCc) != ""){ $headers .= "\nCc: ".$SendCc; }
$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=\"windows-874\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n";
/********************************************** Attach File Start ********************************************/ $ChkAttnID = 0; for($i = 0; $i < $CnAttFile; $i++){ if($AttFileCheck[$i] == "Y" and is_file($AttFilePath[$i])){ $ChkAttnID = $i; } } for($i = 0; $i < $CnAttFile; $i++){ if($AttFileCheck[$i] == "Y" and is_file($AttFilePath[$i])){ $fileatt_type = $AttFileType[$i]; // ประเภทพไฟล์ เช่น pdf จะได้เป็น application/pdf $AttachFile = $AttFilePath[$i]; // ตำแหน่งที่เก็บไฟล์บน server $AttachFileName = $AttFileName[$i]; // ชื่อไฟล์ที่จะให้แสดงตอนส่งเมลล์ไป $fileatt_name = $AttachFileName;
$file = fopen($AttachFile,'rb'); $data = fread($file,filesize($AttachFile)); fclose($file); $data = chunk_split(base64_encode($data)); if($ChkAttnID == $i){ $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; }else{ $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}\n"; } } } /********************************************** Attach File End ********************************************/
$ok = mail($email_to, $email_subject, $email_message, $headers);
?>
:wanwan003: :wanwan003: :wanwan003:
หัวข้อ: Re: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
เริ่มหัวข้อโดย: Fallen ที่ 07 ธันวาคม 2017, 12:13:03
ถ้าใช้พวก phpMailer มันง่ายกว่าไงครับ และรองรับการใช้งานได้หลากหลายกว่า อาจจะยุ่งตอนเริ่มต้น แลัตอน set ค่าบางอย่าง แต่ถ้าเริ่มได้แล้วที่เหลือง่ายมากครับ ส่วนเรื่องส่งเมลล์แนบไฟล์ด้วย function mail ของ php เอาตัวอย่างของผมไปศึกษาดูครับ **ผมข้ามหน้า form ไปนะครับ เป็นตัวที่ผมทำให้ลูกค้า เอามาแบ่งปันครับ** **ในหน้า form ส่งเมลล์ ส่วนของไฟล์ จะให้เลือกได้ว่าจะเอาไฟล์อะไรส่งไปบ้าง (code มันเลยยุ่งๆหน่อย)** <? $detail = " <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-874\"> <title>".$SubJect."</title> </head> <body>".$MailDetail."</body> </html> ";
$email_from = $SendFrom; // Who the email is from $email_subject = $subject; // The Subject of the email $email_message = $detail;// Message that the email has in it $email_to = $SendTo; // Who the email is too
$headers = "From: ".$email_from; if(trim($SendCc) != ""){ $headers .= "\nCc: ".$SendCc; }
$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=\"windows-874\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n";
/********************************************** Attach File Start ********************************************/ $ChkAttnID = 0; for($i = 0; $i < $CnAttFile; $i++){ if($AttFileCheck[$i] == "Y" and is_file($AttFilePath[$i])){ $ChkAttnID = $i; } } for($i = 0; $i < $CnAttFile; $i++){ if($AttFileCheck[$i] == "Y" and is_file($AttFilePath[$i])){ $fileatt_type = $AttFileType[$i]; // ประเภทพไฟล์ เช่น pdf จะได้เป็น application/pdf $AttachFile = $AttFilePath[$i]; // ตำแหน่งที่เก็บไฟล์บน server $AttachFileName = $AttFileName[$i]; // ชื่อไฟล์ที่จะให้แสดงตอนส่งเมลล์ไป $fileatt_name = $AttachFileName;
$file = fopen($AttachFile,'rb'); $data = fread($file,filesize($AttachFile)); fclose($file); $data = chunk_split(base64_encode($data)); if($ChkAttnID == $i){ $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; }else{ $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}\n"; } } } /********************************************** Attach File End ********************************************/
$ok = mail($email_to, $email_subject, $email_message, $headers);
?>
:wanwan003: :wanwan003: :wanwan003: ขอบคุณครับ เดวลองเอาไปใช้ดูครับ +1
|