subject = $subject; } // ################################################################### /** * Sets the body text (required) * * @param string Body text */ public function setBodyText($body) { $this->bodyText = $body; } // ################################################################### /** * Sets the HTML body (optional) * * @param string Body HTML */ public function setBodyHtml($body) { $this->bodyHtml = $body; } // ################################################################### /** * Sets the from address * * @param string Sending email address */ public function setFromAddress($address) { $this->from = $address; } // ################################################################### /** * Sets the from display name * * @param string From name */ public function setFromName($name) { $this->fromName = $name; } // ################################################################### /** * Sets any additional headers * * @param string Additional headers separated by a \n */ public function setHeaders($headers) { $this->headers = $headers; } // ################################################################### /** * Sets the character set to send the email in * * @param string Charset */ public function setCharset($charset) { $this->charset = $charset; } // ################################################################### /** * Sends an email to the specified address with the specified * sender, subject, and body. * * @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 */ public function send($address, $name = null, $sendHtml = false) { if (empty($address)) { trigger_error('You need to specify an email address'); } // load the input sanitizer $input = BSRegister::GetType('Input'); if ($input == null) { BSRegister::Debug('ISSO/Input not loaded, so manually doing so'); $input = BSRegister::LoadModule('Input'); } // make sure we have a mailer // TODO - add support for SMTP if (!@ini_get('sendmail_path')) { BSRegister::Debug("email: no sendmail -> not sending"); return false; } // sort out the to addresses $address = $this->_fetchFirstLine($address); $address = trim($input->unsanitize($address)); $name = $this->_fetchFirstLine($name); $name = trim($input->unsanitize($name)); $tostring = ($name == null ? $address : "\"$name\" <$address>"); // sanitize the from field $this->from = $this->_fetchFirstLine($this->from); $this->from = trim($input->unsanitize($this->from)); if (empty($this->from)) { trigger_error('You need to specify a from email address'); } // sanitize the from name $this->fromName = $this->_fetchFirstLine($this->fromName); $this->fromName = ($this->fromName == '' ? $this->from : trim($input->unsanitize($this->fromName))); // sanitize the subject $this->subject = $this->_fetchFirstLine($this->subject); $this->subject = trim($input->unsanitize($this->subject)); if (empty($this->subject)) { trigger_error('You need to specify a subject for the message'); } // sanitize the body $this->bodyText = BSFunctions::ConvertLineBreaks($this->bodyText, $this->delim); $this->bodyText = trim($input->unsanitize($this->bodyText, true)); if (empty($this->bodyText)) { trigger_error('You need to specify body text before sending the message'); } // attach additional headers $headers = BSFunctions::ConvertLineBreaks($this->headers, $this->delim); $headers .= ((!preg_match("#{$this->delim}$#", $headers) AND $headers != '') ? "\n" : '') . "From: \"{$this->fromName}\" <{$this->from}>" . $this->delim; $headers .= "Return-Path: {$this->from}" . $this->delim; $headers .= "X-Mailer: ISSO Mail Framework \$Revision$" . $this->delim; $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-' . BSFunctions::Rand(10); $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"" . $this->delim; $this->bodyHtml = BSFunctions::ConvertLineBreaks($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 { $headers .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->delim; $body = $this->bodyText; } $headers .= "Content-Transfer-Encoding: 8bit" . $this->delim; $headers = trim($headers); // attempt to send the mail! if (mail($tostring, $this->subject, $body, $headers, "-f {$this->from}")) { BSRegister::Debug("email: sent to $address"); } else { BSRegister::Debug("email: error sending to $address"); } } // ################################################################### /** * Fetches the first line of a string * * @param string A string * * @return string The first line of the string */ private function _fetchFirstLine($string) { $string = BSFunctions::ConvertLineBreaks($string); $broken = explode("\n", $string); return $broken[0]; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>