]>
src.bluestatic.org Git - isso.git/blob - mail.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
32 * This framework is a wrapper for the PHP mail function that properly
33 * sends mail with full email headers.
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
44 * Framework registry object
50 * The message recipient's email address
56 * The subject of the message
68 * The message sender's email address
74 * The message sender's display name
80 * Additional message headers
88 function __construct(&$registry)
90 $this->registry
=& $registry;
96 function Mail(&$registry)
98 $this->__construct($registry);
102 * Sends an email to the specified address with the specified
103 * sender, subject, and body.
107 * @return bool Status of the message
111 if (!@ini_get('sendmail_path'))
113 $this->registry
->debug("email: no sendmail -> not sending");
117 $this->to
= $this->_fetch_first_line($this->to
);
118 $this->from
= $this->_fetch_first_line($this->from
);
122 $this->registry
->debug("email: no from -> not sending");
127 $this->from
= trim($this->registry
->unsanitize($this->from
, true));
130 if (!$this->fromname
)
132 $this->fromname
= $this->from
;
136 $this->fromname
= trim($this->registry
->unsanitize($this->fromname
, true));
141 $this->registry
->debug("email: no recipient -> not sending");
146 $this->to
= trim($this->registry
->unsanitize($this->to
));
151 $this->registry
->debug("email: no subject -> not sending");
156 $this->subject
= trim($this->registry
->unsanitize($this->_fetch_first_line($this->subject
), true));
161 $this->registry
->debug("email: no body -> not sending");
166 $this->body
= $this->_convert_line_breaks($this->body
);
167 $this->body
= trim($this->registry
->unsanitize($this->body
, true));
170 $this->headers
= $this->_convert_line_breaks($this->headers
);
171 $this->headers
.= "From: \"{$this->fromname}\" <{$this->from}>\n";
172 $this->headers
.= "Return-Path: {$this->from}\n";
173 $this->headers
.= "X-Mailer: ISSO Mail Framework \$Revision$\n";
174 $this->headers
.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
175 $this->headers
.= "Content-Transfer-Encoding: 7bit\n";
177 if (mail($this->to
, $this->subject
, $this->body
, trim($this->headers
), "-f {$this->from}"))
179 $this->registry
->debug("email: sent -> good");
184 $this->registry
->debug("email: sent -> error");
190 * Fetches the first line of a string
194 * @param string A string
196 * @return string The first line of the string
198 function _fetch_first_line($string)
200 $string = $this->_convert_line_breaks($string);
201 $broken = explode("\n", $string);
206 * Changes line breaks into one format
211 * @param string New line break (default is UNIX format)
213 * @return string Text with one type of line break
215 function _convert_line_breaks($text, $convert_to = "\n")
218 $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text);
219 $text = str_replace("\n", $convert_to, $text);
224 /*=====================================================================*\
225 || ###################################################################
228 || ###################################################################
229 \*=====================================================================*/