name) * @var array * @access private */ var $to = array(); /** * The subject of the message * @var string * @access private */ var $subject = ''; /** * Body plain-text of the message * @var string * @access private */ var $bodytext = ''; /** * HTML multi-part body of the message * @var string * @access private */ var $bodyhtml = ''; /** * The message sender's email address * @var string * @access private */ var $from = ''; /** * The message sender's display name * @var string * @access private */ var $fromname = ''; /** * Additional message headers * @var string * @access private */ var $headers = ''; /** * Whether to send the message as HTML or plain-text * @var bool * @access private */ var $sendhtml = false; /** * Fields array that is used in this module * @var array * @access private */ var $fields = array( 'subject' => array(REQ_YES, null, false), 'bodytext' => array(REQ_YES, null, false), 'bodyhtml' => array(REQ_NO, null, false), 'from' => array(REQ_YES, null, false), 'fromname' => array(REQ_NO, null, false), 'headers' => array(REQ_NO, null, false), 'sendhtml' => array(REQ_NO, null, false) ); // ################################################################### /** * Constructor */ function __construct(&$registry) { $this->registry =& $registry; } // ################################################################### /** * (PHP 4) Constructor */ function Mail(&$registry) { $this->__construct($registry); } // ################################################################### /** * Sets an ISSO field * * @access public * * @param string Field name * @param mixed Value of the field */ function set($name, $value) { $this->registry->do_set($name, $value, 'mail'); } // ################################################################### /** * Gets an ISSO field * * @access public * * @param string Field name * * @return mixed Value of the field */ function get($fieldname) { return $this->registry->do_get($fieldname, 'mail'); } // ################################################################### /** * Adds a to address * * @access public * * @param string Name to send to * @param string Email address */ function to_add($name, $address) { if (isset($this->to["$address"]) AND $name !== null) { return; } if ($this->registry->modules['functions']->is_valid_email($address)) { $this->to["$address"] = $name; } } // ################################################################### /** * Removes a to address by email; if FALSE, it will clear the array * * @access public * * @param string Email address to remove, or FALSE to clear array */ function to_remove($address) { if ($address === false) { $this->to = array(); } else { unset($this->to["$address"]); } } // ################################################################### /** * Returns the list of "to" addresses * * @access public * * @return array List of to-addresses */ function to_fetch() { return $this->to; } // ################################################################### /** * Sends an email to the specified address with the specified * sender, subject, and body. * * @access public * * @return bool Status of the message */ function send() { // check the required stuff $this->registry->check_isso_fields(get_class($this)); if (sizeof($this->to) < 1) { trigger_error('You need at least one email address to send to', E_USER_ERROR); return false; } // make sure we have a mailer // #*# add support for SMTP if (!@ini_get('sendmail_path')) { $this->registry->debug("email: no sendmail -> not sending"); return false; } // sort out the to addresses $tolist = array(); foreach ($this->to AS $address => $name) { $address = $this->_fetch_first_line($address); $address = trim($this->registry->unsanitize($address)); $name = $this->_fetch_first_line($name); $name = trim($this->registry->unsanitize($name)); if ($name == null) { $tolist[] = $address; } else { $tolist[] = "\"$name\" <$address>"; } } // sanitize the from field $this->from = $this->_fetch_first_line($this->from); if (!$this->from) { $this->registry->debug("email: no from -> not sending"); return false; } else { $this->from = trim($this->registry->unsanitize($this->from)); } // sanitize the from name if (!$this->fromname) { $this->fromname = $this->from; } else { $this->fromname = trim($this->registry->unsanitize($this->fromname)); } // sanitize the subject if (!$this->subject) { $this->registry->debug("email: no subject -> not sending"); return false; } else { $this->subject = trim($this->registry->unsanitize($this->_fetch_first_line($this->subject))); } $delim = "\n"; // sanitize the body if (!$this->bodytext) { $this->registry->debug("email: no body -> not sending"); return false; } else { $this->bodytext = $this->registry->modules['functions']->convert_line_breaks($this->bodytext, $delim); $this->bodytext = trim($this->registry->unsanitize($this->bodytext, true)); } // attach additional headers $this->headers = $this->registry->modules['functions']->convert_line_breaks($this->headers); $this->headers .= "From: \"{$this->fromname}\" <{$this->from}>" . $delim; $this->headers .= "Return-Path: {$this->from}" . $delim; $this->headers .= "X-Mailer: ISSO Mail Framework \$Revision$" . $delim; $this->headers .= "MIME-Version: 1.0" . $delim; // see if we need to use mime/multipart if ($this->sendhtml AND $this->fields['bodyhtml'][2] == true) { $boundary = 'ISSO-MULTIPART-' . $this->registry->modules['functions']->rand(10); $this->headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"" . $delim; $this->bodyhtml = $this->registry->modules['functions']->convert_line_breaks($this->bodyhtml, $delim); // first part of the message (plaintext) $body = "--$boundary" . $delim; $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $delim; $body .= "Content-Transfer-Encoding: 8bit" . $delim . $delim; $body .= $this->bodytext . $delim; // add some space between the parts $body .= $delim . $delim . $delim; // second part (html) $body .= "--$boundary" . $delim; $body .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $delim; $body .= "Content-Transfer-Encoding: 8bit" . $delim; $body .= "Content-Disposition: inline" . $delim . $delim; $body .= $this->bodyhtml . $delim; $body .= "--$boundary--"; } else { $this->headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $delim; $body = $this->bodytext; } $this->headers .= "Content-Transfer-Encoding: 8bit" . $delim; $this->headers = trim($this->headers); #echo $body; exit; // attempt to send the mail! foreach ($tolist AS $address) { if (mail($address, $this->subject, $body, $this->headers, "-f {$this->from}")) { $this->registry->debug("email: sent -> good"); return true; } else { $this->registry->debug("email: sent -> error"); return false; } } } // ################################################################### /** * Fetches the first line of a string * * @access private * * @param string A string * * @return string The first line of the string */ function _fetch_first_line($string) { $string = $this->registry->modules['functions']->convert_line_breaks($string); $broken = explode("\n", $string); return $broken[0]; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>