From f006b2d97288fc14f2345e0c898358f5f58ae807 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 21 Feb 2005 02:39:53 +0000 Subject: [PATCH] Added mail framework. *BLIND COMMIT* --- mail.php | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 mail.php diff --git a/mail.php b/mail.php new file mode 100644 index 0000000..011a5e3 --- /dev/null +++ b/mail.php @@ -0,0 +1,170 @@ +debug("email: no sendmail -> not sending"); + return false; + } + + $this->toemail = $this->_fetch_first_line($this->toemail); + $this->fromemail = $this->_fetch_first_line($this->fromemail); + + if (!$this->fromemail) + { + $_isso->debug("email: no from -> not sending"); + return false; + } + else + { + $this->fromemail = trim($_isso->unsanitize($this->fromemail)); + } + + if (!$this->fromname) + { + $this->fromname = $this->fromemail; + } + else + { + $this->fromname = trim($_isso->unsanitize($this->fromname)); + } + + if (!$this->toemail) + { + $_isso->debug("email: no recipient -> not sending"); + return false; + } + else + { + $this->toemail = trim($_isso->unsanitize($this->toemail)); + } + + if (!$this->subject) + { + $_isso->debug("email: no subject -> not sending"); + return false; + } + else + { + $this->subject = trim($_isso->unsanitize($this->_fetch_first_line($subject))); + } + + if (!$this->body) + { + $_isso->debug("email: no body -> not sending"); + return false; + } + else + { + $this->body = $this->_convert_line_breaks($this->body); + $this->body = trim($_isso->unsanitize($this->body)); + } + + $headers = $this->_convert_line_breaks($this->headers, "\n"); + $headers .= "From \"{$this->fromname}\" <{$this->fromemail}>\n"; + $headers .= "Return-Path: {$this->fromemail}\n"; + $headers .= "X-Mailer: ISSO Mail Framework \$Revision$\n"; + $headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; + $headers .= "Content-Transfer-Encoding: 7bit\n"; + $headers = trim($headers); + + if (mail($this->toemail, $this->subject, $this->body, $headers, "-f {$this->fromemail}")) + { + $_isso->debug("email: sent -> good"); + return true; + } + else + { + $_isso->debug("email: sent -> error"); + return false; + } + } + + /** + * Fetches the first line of a string + * + * @param str A string + * + * @return str The first line of the string + */ + function _fetch_first_line($string) + { + $string = $this->_convert_line_breaks($string); + $broken = explode("\r\n", $string); + return $broken[0]; + } + + /** + * Changes line breaks into one format + * + * @param str Text + * @param str New line break (default is Windows DOS format) + * + * @return str Text with one type of line break + */ + function _convert_line_breaks($text, $convert_to = "\r\n") + { + return preg_replace("#(\r|\n|\r\n)#s", $convert_to, trim($text)); + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5