Location: PHPKode > projects > Myphpim > MyPhPim-01.05/includes/mime_cl.inc
<?php
/* This is a class I found somewhere on the net :)
   I just Changed and messed around with the code to get it working As I wanted it to.
   credits go to:
	Alex Rozhik
	hide@address.com
	http://www.ziet.zhitomir.ua/~rozhik/php3/mimemail/
*/

/* This is Version 1.4
* Notes from hide@address.com 25 Mar 2000:
* Improvements: Multi attachmends in one e-mail, ability to post html & plain trext, up to 3x speed improved.
* USSAGE - mimetype example for attacment
* $m = new CMIMEMail($to,$from,$subject);
* $m->mailbody("This is simply text","<html><body><h1>This is HTML text</h1>");
* $m->attach("example.html","text/html",$filebody);
* $m->attachFile("resume.gif","image/gif");
* $m->send();
*******
* To Do:
* 1 Test with different Mail clients
*/



class CMIMEMail {
	var $to;
 	var $boundary;
 	var $smtp_headers;
 	var $filename_real;
 	var $body_plain;
 	var $body_html;
	var $atcmnt;
 	var $att;
 	var $atcmnt_type;

//###################################################################



 	function CMIMEMail($to, $cc, $bcc, $from,$subject,$att, $priority=3) {
   		$this->att=$att;
   		$this->to=$to ; 
   		$this->cc=$cc;
   		$this->bcc=$bcc;
   		$this->from=$from;
   		$this->subject=$subject ; $this->priority=$priority;
   		$this->boundary="----=_NextPart_".time()."_".md5(time())."_";
 	}

//###################################################################

 	function  mailbody( $plain, $html="" ) {
   		$this->body_plain=$plain;
   		$this->body_html=$html;
 	}

//###################################################################
 
	function  attach( $name, $content_type, $data ) {
 	}

//###################################################################

 	function  attachfile_raw( $fname, $mailFileName, $content_type ) {
   		if($f=fopen($fname,"r")) {
    			$this->atcmnt[$mailFileName]=fread($f,filesize($fname));
    			$this->atcmnt_type[$mailFileName]=$content_type;
    			fclose($f);
  		} 
 	}

//###################################################################

	function  attachfile( $fname, $content_type ) {
    		$this->attachfile_raw($fname,$fname,$content_type);
 	}

//###################################################################

	function  clear() {
   		unset( $atcmnt );
   		unset( $atcmnt_type );
 	}

//###################################################################

	function  makeheader( ) {
   		$date = date( 'j D M Y, H:i:s T');
   		$out="Date: " . $date ."\r\n";
   		$out.="To: " .$this->to."\r\n";
   		$out.="Cc: " .$this->cc."\r\n";
   		$out.="Bcc: " .$this->bcc."\r\n";
   		$out.="From: ".$this->from."\r\n";
   		$out.="Reply-To: ".$this->from."\r\n";
   		$out.="Subject: ".$this->subject."\r\n";
   		if ( $this->att != 0 ) {
   			$out.="MIME-Version: 1.0\r\n".
			"Content-Type: multipart/mixed;\r\n\tboundary=\"".$this->boundary."\"\r\n".
			"X-Priority: ".$this->priority."\r\n".
			"X-Mailer: MyPhPim\r\n";
   		} else {
			$out.="MIME-Version: 1.0\r\n".
			"Content-Type: text/plain\r\n".
			"X-Priority: ".$this->priority."\r\n".
			"X-Mailer: MyPhPim\r\n";
   		}
   		return $out;
 	}

//###################################################################

	function  makebody( ) {
   		if ( $this->att != 0 ) {
   			$boundary2= "----=_NextAttachedPart_".time()."_".md5(time()+101)."_\r\n";
   			$out="";
   			if( " ".$this->body_html!=" " ) {
     				$out="\r\nThis is a multi-part message in MIME format.\r\n\r\n";
     				$out.="--".$this->boundary."\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"$boundary2\"\r\n";
     				$out.="$body_plan\r\n".
	   			"--$boundary2\nContent-Type: text/plain\r\n".
#	   			"Content-Disposition: inline\r\n".
	   			"Content-Transfer-Encoding: quoted-printable\r\n\r\n".
	   			$this->body_plain.
	   			"\r\n\r\n--$boundary2\r\n".
	   			"Content-Type: text/html\r\n".
#	   			"Content-Disposition: attachment;\r\n\tfilename=\"message.html\"\r\n".
           			"Content-Transfer-Encoding: quoted-printable\r\n".
	   			"\r\n$this->body_html\r\n\r\n".
	   			"--$boundary2--\r\n";
   			} else {
     				$out="\r\n\r\nThis is a multi-part message in MIME format.\r\n\r\n";
     				$out.="--".$this->boundary."\r\n".
				"Content-Type: text/plain\r\n".
				"Content-Transfer-Encoding: quoted-printable\r\n\r\n".
				$this->body_plain.
				"\r\n\r\n--".$this->boundary.
				"\r\n";
   			}
   			if( is_array( $this->atcmnt_type ) ) {
     				reset( $this->atcmnt_type);
     				while( list($name, $content_type) = each($this->atcmnt_type) ) {
					$basename = basename ( $name );
       					$out.="\r\n--".$this->boundary."\r\nContent-Type: $content_type\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"$basename\"\r\n\r\n".
         				chunk_split(base64_encode($this->atcmnt[$name]))."\r\n";
     				}   
   			}
   			$out.="\r\n--".$this->boundary."--\r\n";
   		} else {
			$out= "\r\n".$this->body_plain ."\r\n";
   		}
   		return $out;
 	}

//###################################################################

	function  send ( ){
		$sock = new SocketCl;
		$body = $this->makebody( );
		$header = $this->makeheader( );
		$smtpconn = $sock->sendmessage ( $this->to, $header, $body );
		return $smtpconn;
 	}

//###################################################################

	function  sendto($email){
   		mail( $email, $this->subject, $this->makebody(),$this->makeheader() );
	}
}

?>
Return current item: Myphpim