|
|
|
รบกวนถามเรื่องการเขียน code ส่งเมล์โดย Attach ครับของผม Attach รูปไปแต่ข้อความไม่ไปครับ |
|
|
|
|
|
|
|
Code (PHP)
$id_order=$_POST["id_order"];
$po_num=$_POST["po_num"];
$name=$_POST["cus_name"];
$email=$_POST["cus_email"];
$company=$_POST["cus_compamy"];
$address=$_POST["cus_address"];
$country=$_POST["country"];
$province=$_POST["province"];
$tel=$_POST["cus_tel"];
$date_tranfer=$_POST["startdate"];
$time=$_POST["time"];
$amount=$_POST["amount"];
$bank=$_POST["bank"];
$fileupload=$_FILES['file']['tmp_name'];
$fileupload_name=$_FILES['file']['name'];
$fileupload_size=$_FILES['file']['size'];
$fileupload_type=$_FILES['file']['type'];
$amountshow=number_format($amount,"2");
$date_order=date("Y-m-d");
if ($fileupload) {
$array_last=explode(".",$fileupload_name);
$c=count($array_last) -1;
$lastname=strtolower($array_last[$c]);
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg" or $lastname=="png") {
$imagename=$po_num.".".$lastname;
if ($lastname =="jpg" or $lastname =="jpeg") {
$image_resize = imagecreatefromjpeg($fileupload);
} else if ($lastname =="png") {
$image_resize = imagecreatefrompng($fileupload);
} else if ($lastname =="gif") {
$image_resize = imagecreatefromgif($fileupload);
}
$image_size=getimagesize($fileupload);
$image_w=$image_size[0];
$image_h=$image_size[1];
if ($image_w > 800) {
$new_w = 800;
$new_h = round(($new_w/$image_w)*$image_h);
$new_image = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($new_image, $image_resize,0,0,0,0,$new_w,$new_h,$image_w,$image_h);
if ($lastname =="jpg" or $lastname =="jpeg") {
imagejpeg($new_image,"administrator/slip/$imagename");
} else if ($lastname =="png") {
imagepng($new_image,"administrator/slip/$imagename");
} else if ($lastname =="gif") {
imagegif($new_image,"administrator/slip/$imagename");
}
imagedestroy($image_resize);
imagedestroy($new_image);
} else if ($image_w <= 800) {
$new_w = $image_w;
$new_h = round(($new_w/$image_w)*$image_h);
$new_image = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($new_image, $image_resize,0,0,0,0,$new_w,$new_h,$image_w,$image_h);
if ($lastname =="jpg" or $lastname =="jpeg") {
imagejpeg($new_image,"administrator/slip/$imagename");
} else if ($lastname =="png") {
imagepng($new_image,"administrator/slip/$imagename");
} else if ($lastname =="gif") {
imagegif($new_image,"administrator/slip/$imagename");
}
imagedestroy($image_resize);
imagedestroy($new_image);
}
}
}
$strSid = md5(uniqid(time()));
$pathname="administrator/slip";
$strMessage = "My Body & <b>My Description</b>";
$strTo = "[email protected]";
$strSubject = "Inform Payment Transfer PO. Number : $po_num";
$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=utf-8<br>"; // or UTF-8 //
$strHeader .= "From: $email";
$strMessage = "";
$strMessage .= "<br>";
$strMessage .= "Customer Name : $name<br>";
$strMessage .= "From : $company<br>";
$strMessage .= "I'm transfer money to www.hydraulic-smm.com <br>";
$strMessage .= "PO. Number : $po_num <br>";
$strMessage .= "Transfer Date : $date_transfer <br>";
$strMessage .= "Transfer Time : $time <br>";
$strMessage .= "From Bank : $bank <br>";
$strMessage .= "Amount Transfer : $amountshow THB <br>";
$strMessage .= "Please check the transfer. <br>";
$strMessage .= "Thank you very much <br>";
$strMessage .= "<br>";
$strMessage .= "Best regards<br>";
$strMessage .= "$name<br>";
$strMessage .= "$company<br>";
$strMessage .= "$address<br>";
$strMessage .= "$province<br>";
$strMessage .= "$country<br>";
$strMessage .= "$tel <br>";
$strMessage .= "$email<br>";
$strContent = chunk_split(base64_encode(file_get_contents($pathname."/".$imagename)));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$imagename."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$imagename."\"\n\n";
$strHeader .= $strContent."\n\n";
$flgSend = mail($strTo,$strSubject,$strMessage,$strHeader);
header( "Location: alertorder.php?alert=complete" );
?>
ผมเอา Code จากกระทู้นี้ https://www.thaicreate.com/php/php-send-email-upload-zip-attach-files.html มาลองประยุกต์ดุน่ะครับให้เป็นการแนบไฟล์ภาพ ปรากฏว่าไฟล์ภาพที่แนบส่งเมล์ไปครับ แต่ข้อความทั้งหลายไม่ไปเลยครับ มันไปแต่รูปอ่ะครับ ลองแก้ไปมาพักใหญ่ก็ยังไม่ได้ เลยอยากจะรบกวนช่วยดูหน่อยครับว่ามันผิดพลาดตรงไหนน่ะครับ ขอบคุณมากครับ
Tag : PHP
|
|
|
|
|
|
Date :
2012-11-22 08:20:49 |
By :
tony78 |
View :
1085 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้พวก Library จะง่ายกกว่าน่ะครับ เช่น
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Sending Email</title>
</head>
<body>
<?
require_once("mimemail.inc.php");
$mail = new MIMEMAIL("HTML"); // HTML Format
$mail->senderName = "Mr.Weerachai Nukitram";
$mail->senderMail = "[email protected]";
$mail->cc = "Mr.Surachai Sirisart<[email protected]>";
$mail->bcc = "[email protected]";
$mail->subject = "Test Send Mail";
$mail->body = "My Body & <b>My Description</b>"; // OR: $mail->body = "path_to_file/filename";
$mail->attachment[] = "thaicreate1.txt";
$mail->attachment[] = "thaicreate2.txt";
$mail->create();
//*** To ***//
$mail->send("[email protected]");
$mail->send("[email protected],[email protected],[email protected]");
echo "Email Sending.";
?>
</body>
</html>
Go to : PHP Mail Class (MIMEMAIL V 1.5)
|
|
|
|
|
Date :
2012-11-22 08:46:40 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนอีกนิดครับ ถ้าใช้ Library ตัวนี้ผมยังไม่ค่อยเข้าใจเรื่อง การตั้ง path file ตรง attachment เท่าไหร่น่ะครับ อย่างผมทำฟอร์มให้ upload file รูปขึ้นมา ซึ่งแต่ละเครื่อง path จะไม่เหมือนกันเราจะตั้งตรง path ยังไงได้ครับ
|
|
|
|
|
Date :
2012-11-22 09:34:31 |
By :
tony78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|