Return to Snippet

Revision: 21571
at December 15, 2009 16:35 by tclancy


Initial Code
<?
class SystemEmail
{
	var $_to;
	var $_subject;
	var $_message;
	var $_additional_headers = array();
	
	function SystemEmail($to, $subject, $message, $from = false)
	{
		$this->_to = $to;
		$this->_subject = $subject;
		$this->_message = $message;
		
		if ($from)
		{
			$this->_additional_headers[] = $from;
		}
	}
	
	function set_html()
	{
		$this->_additional_headers[] = 'MIME-Version: 1.0' . "
";
		$this->_additional_headers[] = 'Content-type: text/html; charset=iso-8859-1' . "
";
	}
	
	function send()
	{
		$headers = "";
		if (count($this->_additional_headers) > 0)
		{
			foreach ($this->_additional_headers as $header)
			{
				$headers .= $header;
			}
			$headers = substr($headers, 0, strlen($headers)- 2);
		}
		
		if (DEBUG_MODE)
		{
			$this->_message = sprintf("Originally sent to: %s\n\n%s", $this->_to, $this->_message);
			$this->_to = ADMIN_EMAIL;
		}
		@mail($this->_to, $this->_subject, $this->_message, $headers);
	}
}
?>

Initial URL


Initial Description
Just a simple wrapper class that makes sure mail doesn't get sent out when the constant DEBUG_MODE is set to true

Initial Title
Debug Mail Wrapper Class

Initial Tags


Initial Language
PHP