]>
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
51 * The message recipient's email address
58 * The subject of the message
72 * The message sender's email address
79 * The message sender's display name
86 * Additional message headers
93 * Fields array that is used in this module
98 'to' => array(REQ_YES
, null, false),
99 'subject' => array(REQ_YES
, null, false),
100 'body' => array(REQ_YES
, null, false),
101 'from' => array(REQ_YES
, null, false),
102 'fromname' => array(REQ_NO
, null, false),
103 'headers' => array(REQ_NO
, null, false)
106 // ###################################################################
110 function __construct(&$registry)
112 $this->registry
=& $registry;
115 // ###################################################################
117 * (PHP 4) Constructor
119 function Mail(&$registry)
121 $this->__construct($registry);
124 // ###################################################################
130 * @param string Field name
131 * @param mixed Value of the field
133 function set($name, $value)
135 $this->registry
->do_set($name, $value, 'mail');
138 // ###################################################################
140 * Sends an email to the specified address with the specified
141 * sender, subject, and body.
145 * @return bool Status of the message
149 if (!@ini_get('sendmail_path'))
151 $this->registry
->debug("email: no sendmail -> not sending");
155 $this->to
= $this->_fetch_first_line($this->to
);
156 $this->from
= $this->_fetch_first_line($this->from
);
160 $this->registry
->debug("email: no from -> not sending");
165 $this->from
= trim($this->registry
->unsanitize($this->from
));
168 if (!$this->fromname
)
170 $this->fromname
= $this->from
;
174 $this->fromname
= trim($this->registry
->unsanitize($this->fromname
));
179 $this->registry
->debug("email: no recipient -> not sending");
184 $this->to
= trim($this->registry
->unsanitize($this->to
));
189 $this->registry
->debug("email: no subject -> not sending");
194 $this->subject
= trim($this->registry
->unsanitize($this->_fetch_first_line($this->subject
)));
199 $this->registry
->debug("email: no body -> not sending");
204 $this->body
= $this->_convert_line_breaks($this->body
);
205 $this->body
= trim($this->registry
->unsanitize($this->body
, true));
208 $this->headers
= $this->_convert_line_breaks($this->headers
);
209 $this->headers
.= "From: \"{$this->fromname}\" <{$this->from}>\n";
210 $this->headers
.= "Return-Path: {$this->from}\n";
211 $this->headers
.= "X-Mailer: ISSO Mail Framework \$Revision$\n";
212 $this->headers
.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
213 $this->headers
.= "Content-Transfer-Encoding: 7bit\n";
215 if (mail($this->to
, $this->subject
, $this->body
, trim($this->headers
), "-f {$this->from}"))
217 $this->registry
->debug("email: sent -> good");
222 $this->registry
->debug("email: sent -> error");
227 // ###################################################################
229 * Fetches the first line of a string
233 * @param string A string
235 * @return string The first line of the string
237 function _fetch_first_line($string)
239 $string = $this->_convert_line_breaks($string);
240 $broken = explode("\n", $string);
244 // ###################################################################
246 * Changes line breaks into one format
251 * @param string New line break (default is UNIX format)
253 * @return string Text with one type of line break
255 function _convert_line_breaks($text, $convert_to = "\n")
258 $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text);
259 $text = str_replace("\n", $convert_to, $text);
264 /*=====================================================================*\
265 || ###################################################################
268 || ###################################################################
269 \*=====================================================================*/