script ส่งเมล์นี้
1. ต่างกับ contact form ยังไงเหรอครับ เพราะ contact form มันส่งเข้าเมล์ได้เหมือนกันครับ
2. บาง contact form ไม่ include ไฟล์ก็ทำงานได้ ต่างกับอันนี้ยังไงเหรอครับ
3. ถ้าจะเพิ่ม การแนบไฟล์ ต้องทำอย่างไรครับ , แนบแบบหลยไฟล์ ผม งม มาสองวันเเล้ว
<form action='#' method='post' enctype='multipart/form-data'>
<input name='uploads[]' type=file multiple>
<input type='submit'>
</form>

ด้วยความที่มือใหม่จริงๆครับ เอาเท่าที่ตอบได้แระกันนะครับ
ข้อ 1 และ 2 Contact Form คือ ฟอรมในการกรอกข้อมูลติดต่อใช่มั้ย ที่จะมีทั้ง ผู้ติดต่อ หัวข้อ รายละเอียด และอีเมล์ ซึ่งเมื่อกด Submit แล้ว ก็ลงฐานข้อมูล หรือ ส่งเข้าอีเมล์ ศึ่งยังไงก็ต้องเขียน ส่งอีเมล์อยู่แล้ว มันไม่มีทุกสคริปนี่ครับ หรือผมเข้าใจผิด ผมไม่เคยใช้และไม่ถนัด CMS อย่างเช่น wordpress , smf เลยไม่รู้ว่า มันมีการรองรับตรงนี้หรือไม่
ข้อ 3 น่าสนครับ แต่ถ้าคิดออกตอนนี้เลย ผมคงสร้าง input file เพื่ออัพภาพและไฟล์ได้ 5 ช่อง และสร้างฟิลด์ในฐานข้อมูลเพื่อรับค่าไฟล์ 5 ชื่อ อย่างนี้หรือเปล่าครับ
ปล.มือใหม่จริงๆ ครับ เท่าที่ตอบได้

contact form มันจะส่งเข้าเมล์ได้เลยครับ (แต่ถ้าส่งเข้าฐานข้อมูลต้องเขียนเพิ่ม ปัจจุบันผมใช้แบบส่งเข้าเมล์เลยครับง่ายดีอ่ะ)
โค๊ดนี้ใช้ไฟล์เดียว ส่งรูปเข้าเมล์ได้เลยครับ<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_FILES) && (bool) $_FILES) {
$allowedExtensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt");
$files = array();
foreach($_FILES as $name=>$file) {
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
$file_type = $file['type'];
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
if(!in_array($ext,$allowedExtensions)) {
die("File $file_name has the extensions $ext which is not allowed");
}
array_push($files,$file);
}
// email fields: to, from, subject, and so on
$to = "เมล์ของคุณ";
$from = "<<FROM EMAIL>>";
$subject ="test attachment";
$message = "this is a test message";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x]['tmp_name'],"rb");
$data = fread($file,filesize($files[$x]['tmp_name']));
fclose($file);
$data = chunk_split(base64_encode($data));
$name = $files[$x]['name'];
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>mail sent to $to!</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
}
?>
<html>
<body>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="attach1"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
แต่ ผมอยากทำแบบแนบได้ทีเดียวแบบหลายไฟล์ แต่ทำไม่เป็นครับ,รู้แต่ว่าต้องใช้ฟังก์ชั่นตัวนี้
<form action='#' method='post' enctype='multipart/form-data'>
<input name='uploads[]' type=file multiple>
<input type='submit'>
</form>
กับตัวนี้
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";
}
}
ติดอยู่ที่ว่าจะเอามาประกอบร่าง ใส่ตรงไหนแค่นั้นเอง 