Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ขอโค้ด Attach file อยากได้โค้ดที่ใช้ attach file ไปกับเมล์อ่ะค่ะ จะแนบไฟล์รูปอ่ะค่ะ รบกวนผู้รุ้ตอบด้วยนะคะ



 

ขอโค้ด Attach file อยากได้โค้ดที่ใช้ attach file ไปกับเมล์อ่ะค่ะ จะแนบไฟล์รูปอ่ะค่ะ รบกวนผู้รุ้ตอบด้วยนะคะ

 



Topic : 010898

Guest




อยากได้โค้ดที่ใช้ attach file ไปกับเมล์อ่ะค่ะ จะแนบไฟล์รูปอ่ะค่ะ รบกวนผู้รุ้ตอบด้วยนะคะ


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 24 พ.ย. 2549 08:53:44 By : ขนมปัง View : 2316 Reply : 2
 

 

No. 1

Guest


<?php
$m= new Mail; // create the mail
$m->From( "$reply_mail" );
$m->To( "อีเมล์ผู้รับ" );
$m->Subject( "หัวข้อจดหมาย" );

$message= "ข้อความ";
$m->Body( $message); // set the body
//$m->Cc( "[email protected]");
//$m->Bcc( "[email protected]");
$m->Priority(4) ; // set the priority to Low
$m->Attach( "$attache_file", "image/jpeg" ) ; // attach a file of type image/jpeg

//alternatively u can get the attachment uploaded from a form
//and retreive the filename and filetype and pass it to attach methos

$m->Send(); // send the mail
echo "The Fax Already sent:<br><pre>", $m->Get(), "</pre>";


class Mail
{
/*
list of To addresses
@var array
*/
var $sendto = array();
/*
@var array
*/
var $acc = array();
/*
@var array
*/
var $abcc = array();
/*
paths of attached files
@var array
*/
var $aattach = array();
/*
list of message headers
@var array
*/
var $xheaders = array();
/*
message priorities referential
@var array
*/
var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
/*
character set of message
@var string
*/
var $charset = "us-ascii";
var $ctencoding = "7bit";
var $receipt = 0;
var $content_type='';

/*

Mail contructor

*/

function Mail()
{
$this->autoCheck( true );
$this->boundary= "--" . md5( uniqid("myboundary") );
}


function Content_type($contenttype){

$this->content_type=$contenttype;
//echo $this->content_type;
//echo '<br>';
//exit();
}

/*

activate or desactivate the email addresses validator
ex: autoCheck( true ) turn the validator on
by default autoCheck feature is on

@param boolean $bool set to true to turn on the auto validation
@access public
*/
function autoCheck( $bool )
{
if( $bool )
$this->checkAddress = true;
else
$this->checkAddress = false;
}


/*

Define the subject line of the email
@param string $subject any monoline string

*/
function Subject( $subject )
{
$this->xheaders['Subject'] = strtr( $subject, "\r\n" , " " );
}


/*

set the sender of the mail
@param string $from should be an email address

*/

function From( $from )
{

if( ! is_string($from) ) {
echo "Class Mail: error, From is not a string";
exit;
}
$this->xheaders['From'] = $from;
}

/*
set the Reply-to header
@param string $email should be an email address

*/
function ReplyTo( $address )
{

if( ! is_string($address) )
return false;

$this->xheaders["Reply-To"] = $address;

}


/*
add a receipt to the mail ie. a confirmation is returned to the "From" address (or "ReplyTo" if defined)
when the receiver opens the message.

@warning this functionality is *not* a standard, thus only some mail clients are compliants.

*/

function Receipt()
{
$this->receipt = 1;
}


/*
set the mail recipient
@param string $to email address, accept both a single address or an array of addresses

*/

function To( $to )
{

// TODO : test validit้ sur to
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;

if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );

}


/* Cc()
* set the CC headers ( carbon copy )
* $cc : email address(es), accept both array and string
*/

function Cc( $cc )
{
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;

if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );

}



/* Bcc()
* set the Bcc headers ( blank carbon copy ).
* $bcc : email address(es), accept both array and string
*/

function Bcc( $bcc )
{
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}

if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}


/* Body( text [, charset] )
* set the body (message) of the mail
* define the charset if the message contains extended characters (accents)
* default to us-ascii
* $mail->Body( "m้l en fran็ais avec des accents", "iso-8859-1" );
*/
function Body( $body, $charset="windows-874" )
{
$this->body = $body;

if( $charset != "" ) {
$this->charset = strtolower($charset);
if( $this->charset != "us-ascii" )
$this->ctencoding = "8bit";
}
}


/* Organization( $org )
* set the Organization header
*/

function Organization( $org )
{
if( trim( $org != "" ) )
$this->xheaders['Organization'] = $org;
}


/* Priority( $priority )
* set the mail priority
* $priority : integer taken between 1 (highest) and 5 ( lowest )
* ex: $mail->Priority(1) ; => Highest
*/

function Priority( $priority )
{
if( ! intval( $priority ) )
return false;

if( ! isset( $this->priorities[$priority-1]) )
return false;

$this->xheaders["X-Priority"] = $this->priorities[$priority-1];

return true;

}


/*
Attach a file to the mail

@param string $filename : path of the file to attach
@param string $filetype : MIME-type of the file. default to 'application/x-unknown-content-type'
@param string $disposition : instruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment") possible values are "inline", "attachment"
*/

function Attach($filename,$filetype = "",$disposition = "inline")
{

if( $filetype == "" )
$filetype = "application/x-unknown-content-type";
//$filetype = "text/plain";



$this->aattach[] = $filename;


$this->actype[] = $filetype;
$this->adispo[] = $disposition;

}

/*

Build the email message

@access protected

*/
function BuildMail()
{

// build the headers
$this->headers = "";
// $this->xheaders['To'] = implode( ", ", $this->sendto );

if( count($this->acc) > 0 )
$this->xheaders['CC'] = implode( ", ", $this->acc );

if( count($this->abcc) > 0 )
$this->xheaders['BCC'] = implode( ", ", $this->abcc );


if( $this->receipt ) {
if( isset($this->xheaders["Reply-To"] ) )
$this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
else
$this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
}

if( $this->charset != "" ) {
//global $contenttype;
$content_type=$this->content_type;
$this->xheaders["Mime-Version"] = "1.0";
$this->xheaders["Content-Type"] = "$content_type; charset=$this->charset";
$this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
}

$this->xheaders["X-Mailer"] = "RLSP Mailer";

// include attached files
if( count( $this->aattach ) > 0 ) {

$this->_build_attachement();
} else {
$this->fullBody = $this->body;
}

reset($this->xheaders);
while( list( $hdr,$value ) = each( $this->xheaders ) ) {
if( $hdr != "Subject" )
$this->headers .= "$hdr: $value\n";
}


}

/*
fornat and send the mail
@access public
*/

function Send()
{
//global $filename;

$this->BuildMail();

$this->strTo = implode( ", ", $this->sendto );


$res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );

}



/*
* return the whole e-mail , headers + message
* can be used for displaying the message in plain text or logging it
*/

function Get()
{
$this->BuildMail();
$mail = "To: " . $this->strTo . "\n";
$mail .= $this->headers . "\n";
$mail .= $this->fullBody;
return $mail;
}


/*
check an email address validity
@access public
@param string $address : email address to check
@return true if email adress is ok
*/

function ValidEmail($address)
{
if( ereg( ".*<(.+)>", $address, $regs ) ) {
$address = $regs[1];
}
if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
return true;
else
return false;
}


/*

check validity of email addresses
@param array $aad -
@return if unvalid, output an error message and exit, this may -should- be customized

*/

function CheckAdresses( $aad )
{
for($i=0;$i< count( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
echo "Class Mail, method Mail : invalid address $aad[$i]";
exit;
}
}
}


/*
check and encode attach file(s) . internal use only

*/

function _build_attachement()
{

$this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";

$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
$this->fullBody .= "Content-Type: text/html; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";

$sep= chr(13) . chr(10);

$ata= array();
$k=0;
// for each attached file, do...
for( $i=0; $i < count( $this->aattach); $i++ ) {

$filename = $this->aattach[$i];
$basename = basename($filename);
$ctype = $this->actype[$i]; // content-type
$disposition = $this->adispo[$i];
/*getting the original name of the file */

//echo $original_filename;

if( ! file_exists( $filename) ) {
echo "Class Mail, method attach : file $filename can't be found"; exit;
}

/* echo 'filename--'.$filename;
echo '<br>';
*/

/*

the semicolon after the Content-type : $basename is important
since it was not there.This mail program
was not able to see the attachment for the past 1 month
--Saravanan 20/04/02

*/

$subhdr= "--$this->boundary\nContent-Type: $ctype;\n name=\"$basename\";\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
//$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$filename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$filename\"\n";
$ata[$k++] = $subhdr;
// non encoded line length
$linesz= filesize( $filename)+1;
$fp= fopen( $filename, 'r' );
$ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));

fclose($fp);

}

$this->fullBody .= implode($sep, $ata);

//echo $this->fullBody;
}


} // class Mail



?>




-------------------------ลองใช้โค้ดนี้ดูครับ -------------------------------------






Date : 25 พ.ย. 2549 15:18:05 By : แวะมาดู
 


 

No. 2

Guest


ขอบคุงค่ะ
Date : 28 พ.ย. 2549 14:38:37 By : ขนมปัง
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอโค้ด Attach file อยากได้โค้ดที่ใช้ attach file ไปกับเมล์อ่ะค่ะ จะแนบไฟล์รูปอ่ะค่ะ รบกวนผู้รุ้ตอบด้วยนะคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่