ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

mail.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class mail_1_0_0{
27
38 var $AutoMarkup = false;
39 var $Security = false;
40 var $Tags = false;
41
52 var $Timeout = 0;
53
64 var $LastCallTime = 0;
65
80 function load_settings()
81 {
82 try
83 {
84 $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
85 $CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
86 $Settings->load_settings( $CachedMultyFS->get_config( __FILE__ , 'cf_mail' ) );
87 $this->Timeout = $Settings->get_setting( 'timeout' , 0 );
88 }
89 catch( Exception $e )
90 {
91 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
92 }
93 }
94
109 function __construct()
110 {
111 try
112 {
113 $this->LastCallTime = microtime( true ) - $this->Timeout / 1000000;
114
115 $this->AutoMarkup = get_package( 'page::auto_markup' , 'last' , __FILE__ );
116 $this->Security = get_package( 'security' , 'last' , __FILE__ );
117 $this->Tags = get_package( 'string::tags' , 'last' , __FILE__ );
118 }
119 catch( Exception $e )
120 {
121 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
122 }
123 }
124
151 private function get_headers( $From , $Sender )
152 {
153 try
154 {
155 $Headers = array();
156
157 $Headers [] = "MIME-Version: 1.0\r\n";
158 $Headers [] = "Content-type: text/plain; charset=utf-8\r\n";
159
160 if( $From !== false )
161 {
162 if( $Sender !== false )
163 {
164 $Headers [] = 'From: =?utf-8?B?'.base64_encode( $Sender )."?= <$From>\r\n";
165 }
166 else
167 {
168 $Headers [] = "From: $From\r\n";
169 }
170 }
171 $Headers [] = 'X-Mailer: PHP/'.phpversion();
172
173 return( $Headers );
174 }
175 catch( Exception $e )
176 {
177 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
178 }
179 }
180
203 private function compile_string( $Str )
204 {
205 try
206 {
207 $Str = $this->Tags->compile_ultimix_tags( $Str );
208
209 $this->AutoMarkup->compile_string( $Str );
210
211 return( $Str );
212 }
213 catch( Exception $e )
214 {
215 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
216 }
217 }
218
253 function send_email( $From , $To , $Subject , $Message , $Sender = false )
254 {
255 try
256 {
257 if( microtime( true ) < $this->LastCallTime + $this->Timeout / 1000000 )
258 {
259 usleep( $this->LastCallTime + $this->Timeout / 1000000 - microtime( true ) );
260 }
261
262 $Subject = $this->compile_string( $Subject );
263 $Message = $this->compile_string( $Message );
264
265 $Headers = $this->get_headers( $From , $Sender );
266
267 if( mail( $To , $Subject , $Message , implode( '' , $Headers ) ) === false )
268 {
269 throw( new Exception( 'An error occured while sending email' ) );
270 }
271 }
272 catch( Exception $e )
273 {
274 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
275 }
276 }
277 }
278
279 ?>