registry =& $registry; } // ################################################################### /** * (PHP 4) Constructor */ function Mail(&$registry) { $this->__construct($registry); } // ################################################################### /** * Sets the subject * * @access public * * @param string Subject text */ function setSubject($subject) { $this->subject = $subject; } // ################################################################### /** * Sets the body text (required) * * @access public * * @param string Body text */ function setBodyText($body) { $this->bodytext = $body; } // ################################################################### /** * Sets the HTML body (optional) * * @access public * * @param string Body HTML */ function setBodyHtml($body) { $this->bodyhtml = $body; } // ################################################################### /** * Sets the from address * * @access public * * @param string Sending email address */ function setFromAddress($address) { $this->from = $address; } // ################################################################### /** * Sets the from display name * * @access public * * @param string From name */ function setFromName($name) { $this->fromname = $name; } // ################################################################### /** * Sets any additional headers * * @access public * * @param string Additional headers separated by a \n */ function setHeaders($headers) { $this->headers = $headers; } // ################################################################### /** * Sets the character set to send the email in * * @access public * * @param string Charset */ function setCharset($charset) { $this->charset = $charset; } // ################################################################### /** * Sends an email to the specified address with the specified * sender, subject, and body. * * @access public * * @param string Email address to send to * @param string Name of the recipient * @param bool Send an HTML multipart (if HTML body specified)? * * @return bool Status of the message */ function send($address, $name = null, $sendhtml = false) { if (empty($email)) { trigger_error('You need to specify an email address', E_USER_ERROR); return false; } // make sure we have a mailer // TODO - add support for SMTP if (!@ini_get('sendmail_path')) { $this->registry->debug("email: no sendmail -> not sending"); return false; } // sort out the to addresses $address = $this->_fetch_first_line($address); $address = trim($this->registry->unsanitize($address)); $name = $this->_fetch_first_line($name); $name = trim($this->registry->unsanitize($name)); $tostring = ($name == null ? $address : "\"$name\" <$address>"); // sanitize the from field $this->from = $this->_fetch_first_line($this->from); $this->from = trim($this->registry->unsanitize($this->from)); // sanitize the from name $this->fromname = $this->_fetch_first_line($this->fromname); $this->fromname = ($this->fromname == '' ? $this->from : trim($this->registry->unsanitize($this->fromname))); // sanitize the subject $this->subject = $this->_fetch_first_line($this->subject); $this->subject = trim($this->registry->unsanitize($this->subject)); // sanitize the body $this->bodytext = $this->registry->modules['functions']->convert_line_breaks($this->bodytext, $this->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->delim); $this->headers .= ((!preg_match("#{$this->delim}$#", $this->headers) AND $this->headers != '') ? "\n" : '') . "From: \"{$this->fromname}\" <{$this->from}>" . $this->delim; $this->headers .= "Return-Path: {$this->from}" . $this->delim; $this->headers .= "X-Mailer: ISSO Mail Framework \$Revision$" . $this->delim; $this->headers .= "MIME-Version: 1.0" . $this->delim; // see if we need to use mime/multipart if ($sendhtml AND !empty($this->bodyhtml) == true) { $boundary = 'ISSO-MULTIPART-' . $this->registry->modules['functions']->rand(10); $this->headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"" . $this->delim; $this->bodyhtml = $this->registry->modules['functions']->convert_line_breaks($this->bodyhtml, $this->delim); // first part of the message (plaintext) $body = "--$boundary" . $this->delim; $body .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->delim; $body .= "Content-Transfer-Encoding: 8bit" . $this->delim . $this->delim; $body .= $this->bodytext . $this->delim; // add some space between the parts $body .= $this->delim . $this->delim . $this->delim; // second part (html) $body .= "--$boundary" . $this->delim; $body .= "Content-Type: text/html; charset=\"" . $this->charset . "\"" . $this->delim; $body .= "Content-Transfer-Encoding: 8bit" . $this->delim; $body .= "Content-Disposition: inline" . $this->delim . $this->delim; $body .= $this->bodyhtml . $this->delim; $body .= "--$boundary--"; } else { $this->headers .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->delim; $body = $this->bodytext; } $this->headers .= "Content-Transfer-Encoding: 8bit" . $this->delim; $this->headers = trim($this->headers); // attempt to send the mail! if (mail($tostring, $this->subject, $body, $this->headers, "-f {$this->from}")) { $this->registry->debug("email: sent to $address"); } else { $this->registry->debug("email: error sending to $address"); } } // ################################################################### /** * 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$ || ################################################################### \*=====================================================================*/ ?>