|
 |
|
php ส่งอีเมล์ attachment มีปัญหาเรื่องเขียนโค้ดให้ แนบไฟล์ค่ะ ไม่รู้จะแก้ยังไง |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
// sent mail to Administation
$MailTo = "[email protected]" ;
$MailFrom = $_POST['MailFrom'] ;
$MailSubject = $_POST['MailSubject'] ;
$MailMessage = nl2br($_POST['MailMessage']) ;
$Name = $_POST['Name'] ;
$Address = $_POST['Address'] ;
$Email = $_POST['Email'] ;
$Tel = $_POST['Tel'] ;
$Headers .= "From: ".$MailFrom." <".$MailFrom.">\r\n" ;
$Headers .= "Reply-to: ".$MailFrom." <".$MailFrom."> \r\n" ;
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$MailMessage1 = "";
$MailMessage1 .= "รายละเอียดของหมอ \n" ;
$MailMessage1 .= "********************************************\n" ;
$MailMessage1 .= "เรื่อง: ".$MailSubject."\r\n" ;
$MailMessage1 .= "รายละเอียด: ".$MailMessage."\r\n" ;
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES['fileAttach']['name'];
$strContent = $_FILES['fileAttach']['tmp_name'] ;
$fp = fopen($strContent,"r");
$read = fread($fp , filesize($strContent));
$read = base64_encode($read)."\n";
$read = chunk_split($read);
$MailMessage1 .= "--".$strSid."\n";
$MailMessage1 .= "Content-Type: application/octet-stream; name=".$strFilesName."\n";
$MailMessage1.= "Content-Transfer-Encoding: base64\n";
$MailMessage1 .= "Content-Disposition: attachment; filename=".$strFilesName."\n";
$MailMessage1 .=$read;
$MailMessage1 .= $strContent."\n";
if (mail($MailTo, $MailSubject, $MailMessage1, $Headers))
{
echo "การส่งเมล์สำเร็จ ให้ลองเช็คเมล์ดู";
}
else {
echo "ไม่สามารถส่งเมล์ได้ กรุณาตรวจสอบ";
}
}
//*** End Attachment ***/
$MailMessage1 .= "ชื่อ: ".$Name."\r\n" ;
$MailMessage1 .= "ที่อยู่: ".$Address."\r\n" ;
$MailMessage1 .= "E-mail: ".$Email."\r\n" ;
$MailMessage1 .= "Tel: ".$Tel."\r\n" ;
if(mail($MailTo, $MailSubject, $MailMessage1, $Headers, $MailFrom))
{
echo "<script language = 'javascript'>alert(' Thank you for use our service ');</script>";
echo "<meta http-equiv='refresh' content='0;URL=index.php'>";
}else{
echo "<script language = 'javascript'>alert('Please fill information');</script>";
echo "<meta http-equiv='refresh' content='0;URL=contact-us.php'>";
}
// sent mail to customer
/*
$MailFrom = $_POST['MailFrom'] ;
$to = $Email;
//$from = "From: Chaiya-Aree Dental Lab";
$subject = "บริษัท ไชยา-อารี เด็นตัลแลป จำกัด";
$body = "";
$body .= "เรียน: ".$Name."\r\n";
$body .= " \n";
$body .= "ทางบริษัทไชยา-อารี เด็นตัล แลป ขอขอบพระคุณคุณหมอที่แวะมาเยี่ยมเยียนเว็บไซต์
\n";
$body .= "ทั้งนี้หากคุณหมอต้องการเสนอแนะ หรือแสดงความคิดเห็นใดๆ สามารถใช่ช่องทาง \n";
$body .= "ผ่าน contact us หรือสายตรงคุณไชยา-อารี ตลอด 24 ชั่วโมง \n";
$body .= "\n";
$body .= "สำหรับทันตแพทย์ทุกท่าน รับฟรีปูนสโตนสำหรับ contact us ครั้งแรกทางบริษัทจะทำการจัดส่งปูนสโตนภายในหนึ่งสัปดาห์ \n";
$body .= "\n";
$body .= "\n";
$body .= "ขอแสดงความนับถือ\n";
$body .= "บริษัทไชยา-อารี เด็นตัล แลปจำกัด\n";
$body .= "\n";
$body .= "************************************************** \n";
if(mail($Email, $subject, $body, $Headers, $MailFrom))
{
}
*/
?>
Code (PHP)
<form action="contactsing-model.php" method="post" enctype="multipart/form-data" name="frmMain"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td width="133">เรื่อง <span class="font1">*</span></td>
<td width="264"><input name="MailSubject" type="text" /></td>
</tr>
<tr>
<td>รายละเอียด<span class="font1"> *</span></td>
<td> <textarea name="MailMessage" id="MailSubject" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td>แนบไฟล์</td>
<td><input name="fileAttach" type="file"></td>
</tr>
<tr>
<td>ชื่อ-นามสกุล<span class="font1"> *</span></td>
<td><input name="Name" type="text" placeholder="First and last name" required="required" /></td>
</tr>
<tr>
<td>ที่อยู่</td>
<td><textarea name="Address" id="Address" cols="45" rows="2"></textarea></td>
</tr>
<tr>
<td>อีเมล์ <span class="font1">*</span></td>
<td><input name="Email" type="email" /></td>
</tr>
<tr>
<td>หมายเลขโทรศัพท์ <span class="font1">*</span></td>
<td><input name="Tel" type="tel" required="required" /> </td>
<td><input name="MailFrom" type="hidden" value="Chaiya Aree Dental Lab" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" />
<input type="reset" name="Reset" id="reset" value="Reset" /></td>
</tr>
</table></form>

คือพอมันส่งเข้าเมล์แล้วมันไม่แนบไฟล์ให้ค่ะ อยากให้แนบไฟล์แล้วก็แสดงข้อมูลที่เราต้องการค่ะ
>< แก้มาหลายวันแล้วไม่รู้ทำไมอ่าา
Tag : PHP, HTML/CSS, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-08-29 10:41:31 |
By :
ิbloodflake |
View :
1458 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาจากบทความนั้นเหละค่ะ มาแก้ แต่ไม่รู้ทำไม พอส่งเข้าเมลืแล้วมันไม่แนบแต่กลับขึ้นตามรูปนะค่ะ
>< ช่วยดูให้หน่อยได้ไมค่ะ ว่ามันผิดตรงไหน
|
 |
 |
 |
 |
Date :
2011-08-30 14:46:03 |
By :
bloodflake |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|