ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ไฟล์แนบไม่ไป ไปแต่ข้อความ ผิดตรงไหน รบกวนช่วยดูให้ทีครับ(โค๊ดสั้นๆ)  (อ่าน 1739 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« เมื่อ: 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);

?>
« แก้ไขครั้งสุดท้าย: 17 ตุลาคม 2017, 14:26:48 โดย Fallen » บันทึกการเข้า

imaim09
บุคคลทั่วไป
« ตอบ #1 เมื่อ: 01 พฤศจิกายน 2017, 17:01:57 »

 wanwan013 wanwan013
บันทึกการเข้า
dermapond
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 127
ออฟไลน์ ออฟไลน์

กระทู้: 1,749



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 01 พฤศจิกายน 2017, 17:56:19 »

ไม่มี error log แสดงหรอครับ
บันทึกการเข้า

แสงประกายดอทคอม

WordPress Hosting เร็ว แรง มาก ฟรี SSL ระบบ Cpanel เลือก PHP 4.4-8.2 ได้ รองรับ Node.js, Python
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 06 พฤศจิกายน 2017, 20:03:07 »

ไม่มี error log แสดงหรอครับ

กดปุ๊ปข้อความส่งทันที ไม่มี error เลยครับ
ผมมาลองทดสอบอีกที เหมือนว่า โค๊ดไฟล์แนบมันไม่เกียวอะไรกับ โค๊ดทั้งหมดนี้เลย

 wanwan001
บันทึกการเข้า

infamous
ก๊วนเสียว
*

พลังน้ำใจ: 14
ออฟไลน์ ออฟไลน์

กระทู้: 295



ดูรายละเอียด
« ตอบ #4 เมื่อ: 06 พฤศจิกายน 2017, 21:29:38 »

โค๊ดนี้เหมือนเคยเห็นที่ไหน thaicreate เจ้าเก่า?

ผมไม่แน่ใจว่า skill ของท่านมีขนาดไหน ถ้าไม่อยากปวดหัวกับการส่งเมล์ ลองหา library มาใช้งานดูครับ

เช่น พวก PHPMailer : https://github.com/PHPMailer/PHPMailer

ผมลองเอามาเสียบให้ระบบ ถือว่าทำงานได้ดีเลยทีเดียว ยืดหยุ่นพอสมควรครับ
บันทึกการเข้า
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« ตอบ #5 เมื่อ: 07 พฤศจิกายน 2017, 08:57:35 »

โค๊ดนี้เหมือนเคยเห็นที่ไหน thaicreate เจ้าเก่า?

ผมไม่แน่ใจว่า skill ของท่านมีขนาดไหน ถ้าไม่อยากปวดหัวกับการส่งเมล์ ลองหา library มาใช้งานดูครับ

เช่น พวก PHPMailer : https://github.com/PHPMailer/PHPMailer

ผมลองเอามาเสียบให้ระบบ ถือว่าทำงานได้ดีเลยทีเดียว ยืดหยุ่นพอสมควรครับ

สกิลระดับเริ่มต้นครับ
เอามาจากนั้นเเหละครับ อิอิอิ

พวก library ผมไม่เคยทำเลย เพราะต้อง include อะไรเข้าไป ไม่รุ้ว่าดีกว่า code แนวที่ผมถามยังไงครับ? หรือ ว่ามันเสถียรกว่า และ มีการพัฒนา
บันทึกการเข้า

f206cs
Newbie
*

พลังน้ำใจ: 8
ออฟไลน์ ออฟไลน์

กระทู้: 64



ดูรายละเอียด
« ตอบ #6 เมื่อ: 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
« แก้ไขครั้งสุดท้าย: 07 ธันวาคม 2017, 09:49:10 โดย f206cs » บันทึกการเข้า
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« ตอบ #7 เมื่อ: 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
บันทึกการเข้า

หน้า: [1]   ขึ้นบน
พิมพ์