]>
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 // ###################################################################
144 * @param string Field name
146 * @return mixed Value of the field
148 function get($fieldname)
150 return $this->registry
->do_get($fieldname, 'mail');
153 // ###################################################################
155 * Sends an email to the specified address with the specified
156 * sender, subject, and body.
160 * @return bool Status of the message
164 $this->registry
->check_isso_fields(get_class($this));
166 if (!@ini_get('sendmail_path'))
168 $this->registry
->debug("email: no sendmail -> not sending");
172 $this->to
= $this->_fetch_first_line($this->to
);
173 $this->from
= $this->_fetch_first_line($this->from
);
177 $this->registry
->debug("email: no from -> not sending");
182 $this->from
= trim($this->registry
->unsanitize($this->from
));
185 if (!$this->fromname
)
187 $this->fromname
= $this->from
;
191 $this->fromname
= trim($this->registry
->unsanitize($this->fromname
));
196 $this->registry
->debug("email: no recipient -> not sending");
201 $this->to
= trim($this->registry
->unsanitize($this->to
));
206 $this->registry
->debug("email: no subject -> not sending");
211 $this->subject
= trim($this->registry
->unsanitize($this->_fetch_first_line($this->subject
)));
216 $this->registry
->debug("email: no body -> not sending");
221 $this->body
= $this->registry
->modules
['functions']->convert_line_breaks($this->body
);
222 $this->body
= trim($this->registry
->unsanitize($this->body
, true));
225 $this->headers
= $this->registry
->modules
['functions']->convert_line_breaks($this->headers
);
226 $this->headers
.= "From: \"{$this->fromname}\" <{$this->from}>\n";
227 $this->headers
.= "Return-Path: {$this->from}\n";
228 $this->headers
.= "X-Mailer: ISSO Mail Framework \$Revision$\n";
229 $this->headers
.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
230 $this->headers
.= "Content-Transfer-Encoding: 7bit\n";
232 if (mail($this->to
, $this->subject
, $this->body
, trim($this->headers
), "-f {$this->from}"))
234 $this->registry
->debug("email: sent -> good");
239 $this->registry
->debug("email: sent -> error");
244 // ###################################################################
246 * Fetches the first line of a string
250 * @param string A string
252 * @return string The first line of the string
254 function _fetch_first_line($string)
256 $string = $this->registry
->modules
['functions']->convert_line_breaks($string);
257 $broken = explode("\n", $string);
262 /*=====================================================================*\
263 || ###################################################################
266 || ###################################################################
267 \*=====================================================================*/