Updated file headers to be our new one.
[isso.git] / mail.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $OBJECT = 'Mail Sender';
14 $CLASS = 'Mail';
15 $OBJ = 'mail';
16
17 /**
18 * Mail Sender
19 *
20 * This framework is a wrapper for the PHP mail function that properly
21 * sends mail with full email headers.
22 *
23 * @author Iris Studios, Inc.
24 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
25 * @version $Revision$
26 *
27 */
28 class Mail
29 {
30 /**
31 * Global environment variables
32 *
33 * @var to The recipient
34 * @var subject Subject of the message
35 * @var body Text/body of the email
36 * @var from The sender's email
37 * @var fromname The sender's name
38 * @var headers Additional headers
39 */
40 var $to = '';
41 var $subject = '';
42 var $body = '';
43 var $from = '';
44 var $fromname = '';
45 var $headers = '';
46
47 /**
48 * Sends an email to the specified address with the specified
49 * sender, subject, and body.
50 *
51 * @return bool Status of the message
52 */
53 function send()
54 {
55 global $_isso;
56
57 if (!@ini_get('sendmail_path'))
58 {
59 $_isso->debug("email: no sendmail -> not sending");
60 return false;
61 }
62
63 $this->to = $this->_fetch_first_line($this->to);
64 $this->from = $this->_fetch_first_line($this->from);
65
66 if (!$this->from)
67 {
68 $_isso->debug("email: no from -> not sending");
69 return false;
70 }
71 else
72 {
73 $this->from = trim($_isso->unsanitize($this->from, true));
74 }
75
76 if (!$this->fromname)
77 {
78 $this->fromname = $this->from;
79 }
80 else
81 {
82 $this->fromname = trim($_isso->unsanitize($this->fromname, true));
83 }
84
85 if (!$this->to)
86 {
87 $_isso->debug("email: no recipient -> not sending");
88 return false;
89 }
90 else
91 {
92 $this->to = trim($_isso->unsanitize($this->to));
93 }
94
95 if (!$this->subject)
96 {
97 $_isso->debug("email: no subject -> not sending");
98 return false;
99 }
100 else
101 {
102 $this->subject = trim($_isso->unsanitize($this->_fetch_first_line($this->subject), true));
103 }
104
105 if (!$this->body)
106 {
107 $_isso->debug("email: no body -> not sending");
108 return false;
109 }
110 else
111 {
112 $this->body = $this->_convert_line_breaks($this->body);
113 $this->body = trim($_isso->unsanitize($this->body, true));
114 }
115
116 $this->headers = $this->_convert_line_breaks($this->headers);
117 $this->headers .= "From: \"{$this->fromname}\" <{$this->from}>\n";
118 $this->headers .= "Return-Path: {$this->from}\n";
119 $this->headers .= "X-Mailer: ISSO Mail Framework \$Revision$\n";
120 $this->headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
121 $this->headers .= "Content-Transfer-Encoding: 7bit\n";
122
123 if (mail($this->to, $this->subject, $this->body, trim($this->headers), "-f {$this->from}"))
124 {
125 $_isso->debug("email: sent -> good");
126 return true;
127 }
128 else
129 {
130 $_isso->debug("email: sent -> error");
131 return false;
132 }
133 }
134
135 /**
136 * Fetches the first line of a string
137 *
138 * @param str A string
139 *
140 * @return str The first line of the string
141 */
142 function _fetch_first_line($string)
143 {
144 $string = $this->_convert_line_breaks($string);
145 $broken = explode("\n", $string);
146 return $broken[0];
147 }
148
149 /**
150 * Changes line breaks into one format
151 *
152 * @param str Text
153 * @param str New line break (default is UNIX format)
154 *
155 * @return str Text with one type of line break
156 */
157 function _convert_line_breaks($text, $convert_to = "\n")
158 {
159 $text = trim($text);
160 $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text);
161 $text = str_replace("\n", $convert_to, $text);
162 return $text;
163 }
164 }
165
166 /*=====================================================================*\
167 || ###################################################################
168 || # $HeadURL$
169 || # $Id$
170 || ###################################################################
171 \*=====================================================================*/
172 ?>