Removing @see declarations
[isso.git] / mail.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Mail Sender
24 * mail.php
25 *
26 * @package ISSO
27 */
28
29 $OBJECT = 'Mail Sender';
30 $CLASS = 'Mail';
31 $OBJ = 'mail';
32
33 /**
34 * Mail Sender
35 *
36 * This framework is a wrapper for the PHP mail function that properly
37 * sends mail with full email headers.
38 *
39 * @author Iris Studios, Inc.
40 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
41 * @version $Revision$
42 * @package ISSO
43 *
44 */
45 class Mail
46 {
47 /**
48 * The message recipient's email address
49 * @var string
50 */
51 var $to = '';
52
53 /**
54 * The subject of the message
55 * @var string
56 */
57 var $subject = '';
58
59 /**
60 * Body of the message
61 * @var string
62 */
63 var $body = '';
64
65 /**
66 * The message sender's email address
67 * @var string
68 */
69 var $from = '';
70
71 /**
72 * The message sender's display name
73 * @var string
74 */
75 var $fromname = '';
76
77 /**
78 * Additional message headers
79 * @var string
80 */
81 var $headers = '';
82
83 /**
84 * Sends an email to the specified address with the specified
85 * sender, subject, and body.
86 *
87 * @return bool Status of the message
88 */
89 function send()
90 {
91 global $_isso;
92
93 if (!@ini_get('sendmail_path'))
94 {
95 $_isso->debug("email: no sendmail -> not sending");
96 return false;
97 }
98
99 $this->to = $this->_fetch_first_line($this->to);
100 $this->from = $this->_fetch_first_line($this->from);
101
102 if (!$this->from)
103 {
104 $_isso->debug("email: no from -> not sending");
105 return false;
106 }
107 else
108 {
109 $this->from = trim($_isso->unsanitize($this->from, true));
110 }
111
112 if (!$this->fromname)
113 {
114 $this->fromname = $this->from;
115 }
116 else
117 {
118 $this->fromname = trim($_isso->unsanitize($this->fromname, true));
119 }
120
121 if (!$this->to)
122 {
123 $_isso->debug("email: no recipient -> not sending");
124 return false;
125 }
126 else
127 {
128 $this->to = trim($_isso->unsanitize($this->to));
129 }
130
131 if (!$this->subject)
132 {
133 $_isso->debug("email: no subject -> not sending");
134 return false;
135 }
136 else
137 {
138 $this->subject = trim($_isso->unsanitize($this->_fetch_first_line($this->subject), true));
139 }
140
141 if (!$this->body)
142 {
143 $_isso->debug("email: no body -> not sending");
144 return false;
145 }
146 else
147 {
148 $this->body = $this->_convert_line_breaks($this->body);
149 $this->body = trim($_isso->unsanitize($this->body, true));
150 }
151
152 $this->headers = $this->_convert_line_breaks($this->headers);
153 $this->headers .= "From: \"{$this->fromname}\" <{$this->from}>\n";
154 $this->headers .= "Return-Path: {$this->from}\n";
155 $this->headers .= "X-Mailer: ISSO Mail Framework \$Revision$\n";
156 $this->headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
157 $this->headers .= "Content-Transfer-Encoding: 7bit\n";
158
159 if (mail($this->to, $this->subject, $this->body, trim($this->headers), "-f {$this->from}"))
160 {
161 $_isso->debug("email: sent -> good");
162 return true;
163 }
164 else
165 {
166 $_isso->debug("email: sent -> error");
167 return false;
168 }
169 }
170
171 /**
172 * Fetches the first line of a string
173 *
174 * @param string A string
175 *
176 * @return string The first line of the string
177 */
178 function _fetch_first_line($string)
179 {
180 $string = $this->_convert_line_breaks($string);
181 $broken = explode("\n", $string);
182 return $broken[0];
183 }
184
185 /**
186 * Changes line breaks into one format
187 *
188 * @param string Text
189 * @param string New line break (default is UNIX format)
190 *
191 * @return string Text with one type of line break
192 */
193 function _convert_line_breaks($text, $convert_to = "\n")
194 {
195 $text = trim($text);
196 $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text);
197 $text = str_replace("\n", $convert_to, $text);
198 return $text;
199 }
200 }
201
202 /*=====================================================================*\
203 || ###################################################################
204 || # $HeadURL$
205 || # $Id$
206 || ###################################################################
207 \*=====================================================================*/
208 ?>