All pastes #268282 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-05 15:54 UTC
rendered paste body
class app_form {


	var $subject;
	var $path;
	var $files;
	var $headers;
	var $message;
	var $eol;
	
	function app_form($subject = "Application From Website") {
		
		$this->to = "andy@burkecom.com";
		$this->from = "Application@burkecom.com";
		$this->path = "C:\\Inetpub\\vhosts\\jahlaw.com\\httpdocs\\uploads\\";
		$this->subject = $subject;
		
		
		
		if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
		  $this->eol="\r\n";
		} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
		  $this->eol="\r";
		} else {
		  $this->eol="\n";
		}

		$valid = $this->process_form();
		die("finished");
	
	}
	
	function process_form() {
	
	
		foreach($_POST as $element=>$value ) {
			
			if( trim($value) != "" ) {
				$array[$element] = $value;
			}	
		}
		
		foreach($_FILES as $element=>$value ) {
		
			if (is_uploaded_file($_FILES[$element]['tmp_name'])) {
			
				$file = fopen($_FILES[$element]['tmp_name'],'rb');
				$this->files[$element]['name'] = $_FILES[$element]['name'];
				$this->files[$element]['type'] = $_FILES[$element]['type'];
				$this->files[$element]['size'] = filesize($_FILES[$element]['tmp_name']);
				$this->files[$element]['data'] = fread($file,filesize($_FILES[$element]['tmp_name'])); 
				$this->files[$element]['data'] = chunk_split(base64_encode($this->files[$element]['data']));
				fclose($file);
				
			}
		}
		
		$mime = $this->makeHeaders();
		$this->makeMessage($mime_boundary);

		echo $this->headers;

		$ok = mail($this->to, $this->subject, $this->message, $this->headers);
			if ($ok) {
			 echo "<p>Mail sent! Yay PHP!</p>";
			} else {
			 echo "<p>Mail could not be sent. Sorry!</p>";
			} 
	}// end process form
	
	function makeMessage($mime_boundary) {
				   
		foreach( $this->files as $element=>$value ) {
		
			$message .= "--".$mime_boundary.$this->eol;
			$message .= "Content-Type: ".$this->files[$element]['type']."; name=\"".$this->files[$element]['name']."\"".$this->eol;  // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
			$message .= "Content-Transfer-Encoding: base64".$this->eol;
			$message .= "Content-Disposition: attachment; filename=\"".$this->files[$element]['name']."\"".$this->eol.$this->eol; // !! This line needs TWO end of lines !! IMPORTANT !!
			$message .= $this->files[$element]['data'].$this->eol.$this->eol;
			# Setup for text OR html
			$message .= "Content-Type: multipart/alternative".$this->eol;			
		}
		
		# Text Version
		$message .= "--".$mime_boundary.$this->eol;
		$message .= "Content-Type: text/plain; charset=iso-8859-1".$this->eol;
		$message .= "Content-Transfer-Encoding: 8bit".$this->eol;
		$message .= "This is a multi-part message in MIME format.".$this->eol;
		$message .= "If you are reading this, please update your email-reading-software.".$this->eol;
		$message .= "+ + Text Only Email from Genius Jon + +".$this->eol.$this->eol;
		
		# HTML Version
		$message .= "--".$mime_boundary.$this->eol;
		$message .= "Content-Type: text/html; charset=iso-8859-1".$this->eol;
		$message .= "Content-Transfer-Encoding: 8bit".$this->eol;
		$message .= "+ + Text Only Email from Genius Jon + +".$this->eol.$this->eol;
		
		$msg .= "--".$mime_boundary."--".$this->eol.$this->eol; 

		$this->message = $message;
	}
	
	function makeHeaders() {
	
		$headers .= 'From: John <john@burkecom.com>'.$this->eol;
		$headers .= 'Reply-To: John <john@burkecom.com>'.$this->eol;
		$headers .= 'Return-Path: John <john@burkecom.com>'.$this->eol;    // these two to set reply address
		$headers .= "Message-ID: <".time()." TheSystem@".$_SERVER['SERVER_NAME'].">".$this->eol;
		$headers .= "X-Mailer: PHP v".phpversion().$this->eol;          // These two to help avoid spam-filters
		# Boundry for marking the split & Multitype Headers
		$mime_boundary=md5(time());
		$headers .= 'MIME-Version: 1.0'.$this->eol;
		$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$this->eol; 
	
		$this->headers = $headers;
		return $mime_boundary;
	}
	
}