fix #8131 - chinese translations
[Pman.Core] / NotifySend.php
1 <?php
2 require_once 'Pman.php';
3
4 /**
5  * notification script sender - designed to be run by the Notify script - with many children running
6  * in parallel.
7  *
8  * called with an id of a core_notify element
9  *
10  * uses core_notify - to find an event to object and person.
11  *
12  * uses Events table to log failures
13  * 
14  * 
15  * calls $object->toEmail($person,$last_send, $notify) to generate an email struct with
16  *  array (
17  *      headers =>
18  *      recipients =>
19  *      body =>
20  *  )
21  *
22  *
23  * Note uses configuration
24  *
25  * Pman_Core_NotifySend[host] = 'localhost' << to override direct sending..
26  * Mail[helo] << helo host name
27  * Mail[socket_options] << any socket option.
28  */
29 class Pman_Core_NotifySend_Exception_Success extends Exception {}
30 class Pman_Core_NotifySend_Exception_Fail extends Exception {}
31
32
33 class Pman_Core_NotifySend extends Pman
34 {
35     static $cli_desc = "Send out single notification email (usually called from  Core/Notify)";
36     
37     static $cli_opts = array(
38         'debug' => array(
39             'desc' => 'Turn on debugging (see DataObjects debugLevel )',
40             'default' => 0,
41             'short' => 'v',
42             'min' => 0,
43             'max' => 0,
44             
45         ),
46         'DB_DataObject-debug' => array(
47             'desc' => 'Turn on debugging (see DataObjects debugLevel )',
48             'default' => 0,
49             'short' => 'd',
50             'min' => 1,
51             'max' => 1,
52             
53         ),
54         'force' => array(
55             'desc' => 'Force redelivery, even if it has been sent before or not queued...',
56             'default' => 0,
57             'short' => 'f',
58             'min' => 0,
59             'max' => 0,
60         ),
61         'send-to' => array(
62             'desc' => 'Send the message to this address, rather than the one listed.',
63             'default' => '',
64             'short' => 't',
65             'min' => 0,
66             'max' => 1,
67         )
68         
69         
70         
71     );
72     var $table = 'core_notify';
73     var $error_handler = 'die';
74     
75     function getAuth()
76     {
77         $ff = HTML_FlexyFramework::get();
78         if (!$ff->cli) {
79             $this->errorHandler("access denied");
80         }
81         //HTML_FlexyFramework::ensureSingle(__FILE__, $this);
82         return true;
83         
84     }
85    
86     function get($id,$opts=array())
87     {
88
89         //print_r($opts);
90         if (!empty($opts['DB_DataObject-debug'])) {
91             DB_DataObject::debugLevel($opts['DB_DataObject-debug']);
92         }
93         
94         //DB_DataObject::debugLevel(1);
95         //date_default_timezone_set('UTC');
96         // phpinfo();exit;
97         $force = empty($opts['force']) ? 0 : 1;
98         
99         $w = DB_DataObject::factory($this->table);
100
101         if (!$w->get($id)) {
102             $this->errorHandler("invalid id\n");
103         }
104
105         if (!$force && !empty($w->sent) && strtotime($w->act_when) < strtotime($w->sent)) {
106             
107             
108             $this->errorHandler("send repeat to early\n");
109         }
110         if (!empty($opts['debug'])) {
111             print_r($w);
112             $ff = HTML_FlexyFramework::get();
113             if (!isset($ff->Core_Mailer)) {
114                 $ff->Core_Mailer = array();
115             }
116             HTML_FlexyFramework::get()->Core_Mailer['debug'] = true;
117         }
118         
119         $sent = (empty($w->sent) || preg_match('/^0000/', $w->sent)) ? false : true;
120         
121         if (!$force && (!empty($w->msgid) || $sent)) {
122             $ww = clone($w);
123             if (!$sent) { 
124                 $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
125                 $w->update($ww);
126             }    
127             $this->errorHandler("message has been sent already.\n");
128         }
129         
130         $o = $w->object();
131         
132         if ($o === false)  {
133             
134             $ev = $this->addEvent('NOTIFY', $w,
135                             "Notification event cleared (underlying object does not exist)" );;
136             $ww = clone($w);
137             $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
138             $w->msgid = '';
139             $w->event_id = $ev->id;
140             $w->update($ww);
141             $this->errorHandler(date('Y-m-d h:i:s ') . 
142                      "Notification event cleared (underlying object does not exist)" 
143                     ."\n");
144         }
145      
146         
147         
148         $p = $w->person();
149         
150         if (isset($p->active) && empty($p->active)) {
151             $ev = $this->addEvent('NOTIFY', $w,
152                             "Notification event cleared (not user not active any more)" );;
153             $ww = clone($w);
154             $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
155             $w->msgid = '';
156             $w->event_id = $ev->id;
157             $w->update($ww);
158             $this->errorHandler(date('Y-m-d h:i:s ') . 
159                      "Notification event cleared (not user not active any more)" 
160                     ."\n");
161             $this->errorHandler("message has been sent already.\n");
162         }
163         
164         
165         // let's work out the last notification sent to this user..
166         $l = DB_DataObject::factory($this->table);
167         
168         $lar = array(
169                 'ontable' => $w->ontable,
170                 'onid' => $w->onid,
171         );
172         // only newer version of the database us this..
173         if (isset($w->person_table)) {
174             $personid_col = strtolower($w->person_table).'_id';
175             if (isset($w->{$personid_col})) {
176                 $lar[$personid_col] = $w->{$personid_col};
177             }
178         }
179         
180         
181         $l->setFrom( $lar );       
182         $l->whereAdd('id != '. $w->id);
183         $l->orderBy('sent DESC');
184         $l->limit(1);
185         $ar = $l->fetchAll('sent');
186         $last = empty($ar) ? date('Y-m-d H:i:s', 0) : $ar[0];
187         
188         // find last event..
189         $ev = DB_DataObject::factory('Events');
190         $ev->on_id = $w->id;                           // int(11)
191         $ev->on_table = $this->table;
192         $ev->limit(1);
193         $ev->orderBy('event_when DESC');
194         $ar = $ev->fetchAll('event_when');
195         $last_event = empty($ar) ? 0 : $ar[0];
196         $next_try_min = 5;
197         if ($last_event) {
198             $next_try_min = floor((time() - strtotime($last_event)) / 60) * 2;
199         }
200         $next_try = $next_try_min . ' MINUTES';
201          
202         // this may modify $p->email. (it will not update it though)
203         $email =  $this->makeEmail($o, $p, $last, $w, $force);
204         
205         if ($email === true)  {
206             
207             $ev = $this->addEvent('NOTIFY', $w,
208                             "Notification event cleared (not required any more)" );;
209             $ww = clone($w);
210             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
211             $w->msgid = '';
212             $w->event_id = $ev->id;
213             $w->update($ww);
214             $this->errorHandler(date('Y-m-d h:i:s ') . 
215                      "Notification event cleared (not required any more)" 
216                     ."\n");
217         }
218         if (is_a($email, 'PEAR_Error')) {
219             $email =array(
220                 'error' => $email->toString()
221             );
222         }
223         
224         if (empty($p) && !empty($email['recipients'])) {
225             // make a fake person..
226             $p = (object) array(
227                 'email' => $email['recipients']
228             );
229         }
230          
231         if ($email === false || isset($email['error']) || empty($p)) {
232             // object returned 'false' - it does not know how to send it..
233             $ev = $this->addEvent('NOTIFYFAIL', $w, isset($email['error'])  ?
234                             $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable); 
235             $ww = clone($w);
236             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
237             $w->msgid = '';
238             $w->event_id = $ev->id;
239             $w->update($ww);
240             $this->errorHandler(date('Y-m-d h:i:s ') . 
241                     (isset($email['error'])  ?
242                             $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable)
243                     ."\n");
244         }
245         
246         
247         if (isset($email['later'])) {
248             $old = clone($w);
249             $w->act_when = $email['later'];
250             $w->update($old);
251             $this->errorHandler(date('Y-m-d h:i:s ') . " Delivery postponed by email creator to {$email['later']}");
252         }
253         
254          
255         if (empty($email['headers']['Message-Id'])) {
256             $HOST = gethostname();
257             $email['headers']['Message-Id'] = "<{$this->table}-{$id}@{$HOST}>";
258             
259         }
260         
261         
262             
263         
264         //$p->email = 'alan@akbkhome.com'; //for testing..
265         //print_r($email);exit;
266         // should we fetch the watch that caused it.. - which should contain the method to call..
267         // --send-to=test@xxx.com
268        
269         if (!empty($email['send-to'])) {
270             $p->email = $email['send-to'];
271         }
272          if (!empty($opts['send-to'])) {
273             $p->email = $opts['send-to'];
274         }
275         
276             // since some of them have spaces?!?!
277         $p->email = trim($p->email);
278       
279         
280         require_once 'Validate.php';
281         if (!Validate::email($p->email, true)) {
282             $ev = $this->addEvent('NOTIFYFAIL', $w, "INVALID ADDRESS: " . $p->email);
283             $ww = clone($w);
284             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
285             $w->msgid = '';
286             $w->event_id = $ev->id;
287             $w->update($ww);
288             $this->errorHandler(date('Y-m-d h:i:s ') . "INVALID ADDRESS: " . $p->email. "\n");
289             
290         }
291         
292         
293         $ff = HTML_FlexyFramework::get();
294         
295         $explode_email = explode('@', $p->email);
296         $dom = array_pop($explode_email);
297         
298         $mxs = $this->mxs($dom);
299         $ww = clone($w);
300
301         // we might fail doing this...
302         // need to handle temporary failure..
303        
304         
305           // we try for 3 days..
306         $retry = 5;
307         if (strtotime($w->act_start) <  strtotime('NOW - 1 HOUR')) {
308             // older that 1 hour.
309             $retry = 15;
310         }
311         
312         if (strtotime($w->act_start) <  strtotime('NOW - 1 DAY')) {
313             // older that 1 day.
314             $retry = 60;
315         }
316         if (strtotime($w->act_start) <  strtotime('NOW - 2 DAY')) {
317             // older that 1 day.
318             $retry = 120;
319         }
320         
321         if ($mxs === false) {
322             // only retry for 2 day son the MX issue..
323             if ($retry < 120) {
324                 $this->addEvent('NOTIFY', $w, 'MX LOOKUP FAILED ' . $dom );
325                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
326                 $w->update($ww);
327                 $this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED\n");
328             }
329             
330             $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email );
331             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
332             $w->msgid = '';
333             $w->event_id = $ev->id;
334             $w->update($ww);
335             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  BAD EMAIL - {$p->email} \n");
336             
337             
338         }
339         
340         
341         
342         
343         if (!$force && strtotime($w->act_start) <  strtotime('NOW - 14 DAY')) {
344             $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - GIVE UP - ". $p->email );
345             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
346             $w->msgid = '';
347             $w->event_id = $ev->id;
348             $w->update($ww);
349             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  GAVE UP TO OLD - {$p->email} \n");
350         }
351         
352         
353         
354         $w->to_email = $p->email; 
355         //$this->addEvent('NOTIFY', $w, 'GREYLISTED ' . $p->email . ' ' . $res->toString());
356         // we can only update act_when if it has not been sent already (only happens when running in force mode..)
357         $w->act_when =  (!$w->act_when || $w->act_when == '0000-00-00 00:00:00') ? date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES')) : $w->act_when;
358         $w->update($ww);
359         
360         $ww = clone($w);   
361         
362         $fail = false;
363         require_once 'Mail.php';
364         
365         $core_domain = DB_DataObject::factory('core_domain');
366         if(!$core_domain->get('domain', $dom)){
367             $core_domain = DB_DataObject::factory('core_domain');
368             $core_domain->setFrom(array(
369                 'domain' => $dom
370             ));
371             $core_domain->insert();
372         }
373                         
374         foreach($mxs as $mx) {
375             
376             if (!isset($ff->Mail['helo'])) {
377                 $this->errorHandler("config Mail[helo] is not set");
378             }
379             $this->debug_str = '';
380             $this->debug("Trying SMTP: $mx / HELO {$ff->Mail['helo']}");
381             $mailer = Mail::factory('smtp', array(
382                     'host'    => $mx ,
383                     'localhost' => $ff->Mail['helo'],
384                     'timeout' => 15,
385                     'socket_options' =>  isset($ff->Mail['socket_options']) ? $ff->Mail['socket_options'] : null,
386                     //'debug' => isset($opts['debug']) ?  1 : 0,
387                     'debug' => 1,
388                     'debug_handler' => array($this, 'debugHandler')
389             ));
390             
391             // if the host is the mail host + it's authenticated add auth details
392             // this normally will happen if you sent  Pman_Core_NotifySend['host']
393              
394             
395             if (isset($ff->Mail['host']) && $ff->Mail['host'] == $mx && !empty($ff->Mail['auth'] )) {
396                 
397                 $mailer->auth = true;
398                 $mailer->username = $ff->Mail['username'];
399                 $mailer->password = $ff->Mail['password'];        
400             }
401             
402             if(!empty($ff->Core_Notify) && !empty($ff->Core_Notify['routes'])){
403                 
404                 // we might want to regex 'office365 as a mx host 
405                 foreach ($ff->Core_Notify['routes'] as $server => $settings){
406                     if(!in_array($dom, $settings['domains'])){
407                         continue;
408                     }
409                     
410                     // what's the minimum timespan.. - if we have 60/hour.. that's 1 every minute.
411                     // if it's newer that '1' minute...
412                     // then shunt it..
413                     
414                     $settings['rate'] = isset( $settings['rate']) ?  $settings['rate']  : 360;
415                     
416                     $seconds = floor((60 * 60) / $settings['rate']);
417                     
418                     $core_notify = DB_DataObject::factory($this->table);
419                     $core_notify->domain_id = $core_domain->id;
420                     $core_notify->whereAdd("
421                         sent >= NOW() - INTERVAL $seconds SECOND
422                     ");
423                     
424                     if($core_notify->count()){
425                         $old = clone($w);
426                         $w->act_when = date("Y-m-d H:i:s", time() + $seconds);
427                         $w->update($old);
428                         $this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
429                     }
430                      
431                     
432                     
433                     $mailer->host = $server;
434                     $mailer->auth = isset($settings['auth']) ? $settings['auth'] : true;
435                     $mailer->username = $settings['username'];
436                     $mailer->password = $settings['password'];
437                     if (isset($settings['port'])) {
438                         $mailer->port = $settings['port'];
439                     }
440                     if (isset($settings['socket_options'])) {
441                         $mailer->socket_options = $settings['socket_options'];
442                         
443                     }
444                     
445                     
446                     break;
447                 }
448                 
449             }
450         
451             
452             $res = $mailer->send($p->email, $email['headers'], $email['body']);
453              
454             
455             if ($res === true) {
456                 // success....
457                 
458                 $successEventName = (empty($email['successEventName'])) ? 'NOTIFYSENT' : $email['successEventName'];
459                 
460                 $ev = $this->addEvent($successEventName, $w, "{$w->to_email} - {$email['headers']['Subject']}");
461                 
462                 $ev->writeEventLog($this->debug_str);
463                 
464                 if(strtotime($w->act_when) > strtotime("NOW")){
465                     $w->act_when = date('Y-m-d H:i:s');
466                 }
467                 
468                 $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
469                 $w->msgid = $email['headers']['Message-Id'];
470                 $w->event_id = $ev->id; // sent ok.. - no need to record it..
471                 $w->domain_id = $core_domain->id;
472                 $w->update($ww);
473                 
474                 // enable cc in notify..
475                 if (!empty($email['headers']['Cc'])) {
476                     $cmailer = Mail::factory('smtp',  isset($ff->Mail) ? $ff->Mail : array() );
477                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
478                     $cmailer->send($email['headers']['Cc'],
479                                   $email['headers'], $email['body']);
480                     
481                 }
482                 
483                 if (!empty($email['bcc'])) {
484                     $cmailer = Mail::factory('smtp', isset($ff->Mail) ? $ff->Mail : array() );
485                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
486                     $res = $cmailer->send($email['bcc'],
487                                   $email['headers'], $email['body']);
488                     if (!$res || is_a($res, 'PEAR_Error')) {
489                         echo "could not send bcc..\n";
490                     } else {
491                         echo "Sent BCC to {$email['bcc']}\n";
492                     }
493                 }
494                 
495                 
496                 $this->errorHandler(date('Y-m-d h:i:s') . " - SENT {$w->id} - {$w->to_email} \n", true);
497             }
498             // what type of error..
499             $code = empty($res->userinfo['smtpcode']) ? -1 : $res->userinfo['smtpcode'];
500             if (!empty($res->code) && $res->code == 10001) {
501                 // fake greylist if timed out.
502                 $code = 421;
503             }
504             
505             if ($code < 0) {
506                 $this->debug($res->message);
507                 continue; // try next mx... ??? should we wait??? - nope we did not even connect..
508             }
509             // give up after 2 days..
510             if (in_array($code, array( 421, 450, 451, 452))   && $next_try_min < (2*24*60)) {
511                 // try again later..
512                 // check last event for this item..
513                 //$errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
514                 $errmsg=  $res->userinfo['smtpcode'] . ': ' .$res->message ;
515                 if (!empty($res->userinfo['smtptext'])) {
516                     $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
517                 }
518                 //print_r($res);
519                 $this->addEvent('NOTIFY', $w, 'GREYLISTED - ' . $errmsg);
520                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
521                 $w->domain_id = $core_domain->id;
522                 $w->update($ww);
523                 
524                 
525                 $this->errorHandler(date('Y-m-d h:i:s') . " - GREYLISTED -  $errmsg \n");
526             }
527             $fail = true;
528             break;
529         }
530         if ($fail || $next_try_min > (2*24*60)) {
531         // fail.. = log and give up..
532             $errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
533             if (isset($res->userinfo['smtptext'])) {
534                 $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
535             }
536             
537             $ev = $this->addEvent('NOTIFYFAIL', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") .
538                        $errmsg);
539             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
540             $w->msgid = '';
541             $w->event_id = $ev->id;
542             $w->domain_id = $core_domain->id;
543             $w->update($ww);
544             $this->errorHandler(date('Y-m-d h:i:s') . ' - FAILED - '. ($fail ? $res->toString() : "RETRY TIME EXCEEDED\n"));
545         }
546         
547         // handle no host availalbe forever...
548         if (strtotime($w->act_start) < strtotime('NOW - 3 DAYS')) {
549             $ev = $this->addEvent('NOTIFYFAIL', $w, "RETRY TIME EXCEEDED - ". $p->email);
550             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
551             $w->msgid = '';
552             $w->event_id = $ev->id;
553             $w->domain_id = $core_domain->id;
554             $w->update($ww);
555             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED - RETRY TIME EXCEEDED\n");
556         }
557         
558         
559         $this->addEvent('NOTIFY', $w, 'NO HOST CAN BE CONTACTED:' . $p->email);
560         $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + 5 MINUTES'));
561         $w->domain_id = $core_domain->id;
562         $w->update($ww);
563         $this->errorHandler(date('Y-m-d h:i:s') ." - NO HOST AVAILABLE\n");
564
565         
566     }
567     function mxs($fqdn)
568     {
569         $ff = HTML_FlexyFramework::get();
570         if (isset($ff->Pman_Core_NotifySend['host'])) {
571             return array($ff->Pman_Core_NotifySend['host']);
572         }
573         
574         $mx_records = array();
575         $mx_weight = array();
576         $mxs = array();
577         if (!getmxrr($fqdn, $mx_records, $mx_weight)) {
578             if (!checkdnsrr($fqdn)) {
579                 return false;
580             }
581             return array($fqdn);
582         }
583         
584         asort($mx_weight,SORT_NUMERIC);
585         
586         foreach($mx_weight as $k => $weight) {
587             $mxs[] = $mx_records[$k];
588         }
589         return $mxs;
590     }
591     
592     /**
593      * wrapper to call object->toEmail()
594      *
595      * return
596      *   {
597         headers : {AssocArray},
598         body: {String}
599         
600         // optional..
601         error :  {String} // error message in log.
602         send-to: {String} // use to override rcpt
603          
604      }
605      **/
606     function makeEmail($object, $rcpt, $last_sent_date, $notify, $force =false)
607     {
608         $m = 'notify'. $notify->evtype;
609         //var_dump(get_class($object) . '::' .$m);
610         if (!empty($notify->evtype) && method_exists($object,$m)) {
611             echo "calling :" . get_class($object) . '::' .$m . "\n";
612             return $object->$m($rcpt, $last_sent_date, $notify, $force);
613         }
614         
615         $type = explode('::', $notify->evtype);
616         
617         if(!empty($type[1]) && method_exists($object,$type[1])){
618             $m = $type[1];
619             echo "calling :" . get_class($object) . '::' .$m . "\n";
620             return $object->$m($rcpt, $last_sent_date, $notify, $force);
621         }
622                 
623         if (method_exists($object, 'toMailerData')) {
624             return $object->toMailerData(array(
625                 'rcpts'=>$rcpt,
626                 'person'=>$rcpt, // added as mediaoutreach used this?
627             )); //this is core_email - i think it's only used for testing...
628             //var_Dump($object);
629             //exit;
630         }
631         
632         return $object->toEmail($rcpt, $last_sent_date, $notify, $force);
633     }
634     
635     function debug($str)
636     {
637         if (empty($this->cli_args['debug'])) {
638             return;
639             
640         }
641         echo $str . "\n";
642     }
643     function output()
644     {
645         $this->errorHandler("done\n");
646     }
647     var $debug_str = '';
648     
649     function debugHandler ($smtp, $message)
650     {
651         $this->debug_str .= strlen($this->debug_str) ? "\n" : '';
652         $this->debug_str .= $message;
653         //echo $message ."\n";
654     }
655     
656     function errorHandler($msg, $success = false)
657     {
658         if($this->error_handler == 'exception'){
659             if($success){
660                 throw new Pman_Core_NotifySend_Exception_Success($msg);
661             }
662             
663             throw new Pman_Core_NotifySend_Exception_Fail($msg);
664         }
665         
666         die($msg);
667         
668         
669     }
670 }