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 in the form of array(email => name)
58 * The subject of the message
65 * Body plain-text of the message
72 * HTML multi-part body of the message
79 * The message sender's email address
86 * The message sender's display name
93 * Additional message headers
100 * Whether to send the message as HTML or plain-text
104 var $sendhtml = false;
107 * Fields array that is used in this module
112 'subject' => array(REQ_YES
, null, false),
113 'bodytext' => array(REQ_YES
, null, false),
114 'bodyhtml' => array(REQ_NO
, null, false),
115 'from' => array(REQ_YES
, null, false),
116 'fromname' => array(REQ_NO
, null, false),
117 'headers' => array(REQ_NO
, null, false),
118 'sendhtml' => array(REQ_NO
, null, false)
121 // ###################################################################
125 function __construct(&$registry)
127 $this->registry
=& $registry;
130 // ###################################################################
132 * (PHP 4) Constructor
134 function Mail(&$registry)
136 $this->__construct($registry);
139 // ###################################################################
145 * @param string Field name
146 * @param mixed Value of the field
148 function set($name, $value)
150 $this->registry
->do_set($name, $value, 'mail');
153 // ###################################################################
159 * @param string Field name
161 * @return mixed Value of the field
163 function get($fieldname)
165 return $this->registry
->do_get($fieldname, 'mail');
168 // ###################################################################
174 * @param string Name to send to
175 * @param string Email address
177 function to_add($name, $address)
179 if (isset($this->to
["$address"]) AND $name !== null)
184 if ($this->registry->modules['functions']->is_valid_email($address))
186 $this->to["$address"] = $name;
190 // ###################################################################
192 * Removes a to address by email; if FALSE, it will clear the array
196 * @param string Email address to remove, or FALSE to clear array
198 function to_remove($address)
200 if ($address === false)
206 unset($this->to
["$address"]);
210 // ###################################################################
212 * Returns the list of "to
" addresses
216 * @return array List of to-addresses
223 // ###################################################################
225 * Sends an email to the specified address with the specified
226 * sender, subject, and body.
230 * @return bool Status of the message
234 $this->registry->check_isso_fields(get_class($this));
236 if (!@ini_get('sendmail_path'))
238 $this->registry->debug("email
: no sendmail
-> not sending
");
242 $this->to = $this->_fetch_first_line($this->to);
243 $this->from = $this->_fetch_first_line($this->from);
247 $this->registry->debug("email
: no from
-> not sending
");
252 $this->from = trim($this->registry->unsanitize($this->from));
255 if (!$this->fromname)
257 $this->fromname = $this->from;
261 $this->fromname = trim($this->registry->unsanitize($this->fromname));
266 $this->registry->debug("email
: no recipient
-> not sending
");
271 $this->to = trim($this->registry->unsanitize($this->to));
276 $this->registry->debug("email
: no subject
-> not sending
");
281 $this->subject = trim($this->registry->unsanitize($this->_fetch_first_line($this->subject)));
286 $this->registry->debug("email
: no body
-> not sending
");
291 $this->body = $this->registry->modules['functions']->convert_line_breaks($this->body);
292 $this->body = trim($this->registry->unsanitize($this->body, true));
295 $this->headers = $this->registry->modules['functions']->convert_line_breaks($this->headers);
296 $this->headers .= "From
: \"{$this
->fromname
}\" <{$this
->from
}>\n";
297 $this->headers .= "Return-Path
: {$this
->from
}\n";
298 $this->headers .= "X
-Mailer
: ISSO Mail Framework \$Revision$\n
";
299 $this->headers .= "Content
-Type
: text
/plain
; charset
=\"iso
-8859-1\"\n";
300 $this->headers .= "Content
-Transfer
-Encoding
: 7bit\n
";
302 if (mail($this->to, $this->subject, $this->body, trim($this->headers), "-f {$this
->from
}"))
304 $this->registry->debug("email
: sent
-> good
");
309 $this->registry->debug("email
: sent
-> error
");
314 // ###################################################################
316 * Fetches the first line of a string
320 * @param string A string
322 * @return string The first line of the string
324 function _fetch_first_line($string)
326 $string = $this->registry->modules['functions']->convert_line_breaks($string);
327 $broken = explode("\n
", $string);
332 /*=====================================================================*\
333 || ###################################################################
336 || ###################################################################
337 \*=====================================================================*/