]>
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
85 // ###################################################################
89 function __construct(&$registry)
91 $this->registry
=& $registry;
94 // ###################################################################
98 function Mail(&$registry)
100 $this->__construct($registry);
103 // ###################################################################
105 * Sends an email to the specified address with the specified
106 * sender, subject, and body.
110 * @return bool Status of the message
114 if (!@ini_get('sendmail_path'))
116 $this->registry
->debug("email: no sendmail -> not sending");
120 $this->to
= $this->_fetch_first_line($this->to
);
121 $this->from
= $this->_fetch_first_line($this->from
);
125 $this->registry
->debug("email: no from -> not sending");
130 $this->from
= trim($this->registry
->unsanitize($this->from
, true));
133 if (!$this->fromname
)
135 $this->fromname
= $this->from
;
139 $this->fromname
= trim($this->registry
->unsanitize($this->fromname
, true));
144 $this->registry
->debug("email: no recipient -> not sending");
149 $this->to
= trim($this->registry
->unsanitize($this->to
));
154 $this->registry
->debug("email: no subject -> not sending");
159 $this->subject
= trim($this->registry
->unsanitize($this->_fetch_first_line($this->subject
), true));
164 $this->registry
->debug("email: no body -> not sending");
169 $this->body
= $this->_convert_line_breaks($this->body
);
170 $this->body
= trim($this->registry
->unsanitize($this->body
, true));
173 $this->headers
= $this->_convert_line_breaks($this->headers
);
174 $this->headers
.= "From: \"{$this->fromname}\" <{$this->from}>\n";
175 $this->headers
.= "Return-Path: {$this->from}\n";
176 $this->headers
.= "X-Mailer: ISSO Mail Framework \$Revision$\n";
177 $this->headers
.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
178 $this->headers
.= "Content-Transfer-Encoding: 7bit\n";
180 if (mail($this->to
, $this->subject
, $this->body
, trim($this->headers
), "-f {$this->from}"))
182 $this->registry
->debug("email: sent -> good");
187 $this->registry
->debug("email: sent -> error");
192 // ###################################################################
194 * Fetches the first line of a string
198 * @param string A string
200 * @return string The first line of the string
202 function _fetch_first_line($string)
204 $string = $this->_convert_line_breaks($string);
205 $broken = explode("\n", $string);
209 // ###################################################################
211 * Changes line breaks into one format
216 * @param string New line break (default is UNIX format)
218 * @return string Text with one type of line break
220 function _convert_line_breaks($text, $convert_to = "\n")
223 $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text);
224 $text = str_replace("\n", $convert_to, $text);
229 /*=====================================================================*\
230 || ###################################################################
233 || ###################################################################
234 \*=====================================================================*/