|
|
|
ส่งแนบเมล์ ไฟล์ ถ้าส่งเมล์เป็นตัวหนังสือส่งได้ แต่ถ้าต้องการแนบไฟล์ได้ด้วยต้อง เขียนโค๊ดอย่างไรคับ |
|
|
|
|
|
|
|
ลองเอาไปประยุกต์ใช้ดูนะ แต่โค้ดนี้เป็นการส่งไฟล์ภาพไปด้วยน่ะ
if($HTTP_POST_VARS[to]||$HTTP_POST_VARS[from])
{ $to=$HTTP_POST_VARS[to];
$from=$HTTP_POST_VARS[from];
$sender=$HTTP_POST_VARS[sender];
$ecard=$HTTP_GET_VARS[ecard];
$subject = "energy fantasia e-card ถึงคุณ";
$message = '
<html>
<head>
<title>Energy Fantasia</title>
</head>
<body>
เพื่อนของคุณ
'
.$sender.
' ได้ส่ง ecard ให้คุณผ่านทางเว็บไซต์<br><br> <a href="http://www.energyfantasia.com">http://www.energyfantasia.com</a><br><br>
<img src=
'
.'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/ecard/ecard$ecard.jpg". //บรรทัดนี้คือการส่งไฟล์ภาพโดยการใส่เข้าไปในส่วนของเนื้อหา
' border=0><br><br>
'
.$cardmessage.
'
</body>
</html>
';
/* To send HTML mail, you can set the Content-type header. */
$headers = "From:".$from."\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=windows-874\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
/* and now mail it */
ini_set(SMTP,"203.150.225.191");
ini_set("sendmail_from",$from);
//mail("[email protected]", "My Subject", "Body");
mail($to, $subject, $message, $headers);
?>
|
|
|
|
|
Date :
7 ก.ค. 2549 13:31:54 |
By :
ริมรั้ว |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?php
class mime_mail {
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;
function mime_mail() {
$this->parts = array();
$this->to = "";
$this->from = "";
$this->subject = "";
$this->body = "";
$this->headers = "";
}
function add_attachment($message, $name = "", $ctype = "application/octet-stream") {
$this->parts [] = array (
"ctype" => $ctype,
"message" => $message,
"encode" => $encode,
"name" => $name
);
}
function build_message($part) {
$message = $part["message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
return "Content-Type: ".$part["ctype"].($part["name"]? "; name = \"".$part["name"]."\"" : "")."\nContent-Transfer-Encoding: $encoding\n\n$message\n";
}
function build_multipart() {
$boundary = "b".md5(uniqid(time()));
$multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";
for($i = sizeof($this->parts)-1; $i>=0; $i--) $multipart .= "\n".$this->build_message($this->parts[$i]). "--$boundary";
return $multipart.= "--\n";
}
function send() {
$mime = "";
if (!empty($this->from)) $mime .= "From: ".$this->from. "\n";
if (!empty($this->headers)) $mime .= $this->headers. "\n";
if (!empty($this->body)) $this->add_attachment($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n".$this->build_multipart();
mail($this->to, $this->subject, "", $mime);
}
}
$attachment = fread(fopen("file.zip", "r"), filesize("file.zip"));
$mail = new mime_mail();
$mail->from = "[email protected]";
$mail->headers = "Errors-To: [[email protected]][email protected][/EMAIL]";
$mail->to = "[email protected]";
$mail->subject = "PHP atachment";
$mail->body = "Get your file!";
$mail->add_attachment("$attachment", "file.zip", "Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEASABIAAD/7QT+UGhvdG9zaG");
$mail->send();
?> แนบไฟล์ แบบนี้สิ สหาย
|
|
|
|
|
Date :
7 ก.ค. 2549 15:48:14 |
By :
โจผีนะ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|