NotifySmtpCheck.php
[Pman.Core] / NotifySmtpCheck.php
1 <?php
2
3 require_once 'Pman.php';
4 require_once "Mail.php";
5 require_once 'Mail/smtpmx.php';
6         
7 class Pman_Core_NotifySmtpCheck extends Pman
8 {
9     static $cli_desc = "Check SMTP";
10  
11     static $cli_opts = array();
12         
13     function get()
14     {
15         $this->check();
16         
17     }
18     
19     function check()
20     {
21         $ff = HTML_FlexyFramework::get();
22         
23         if(
24                 empty($ff->Core_Notify) ||
25                 empty($ff->Core_Notify['routes'])
26         ){
27             return;
28         }
29         
30         $error = array();
31         
32         foreach ($ff->Core_Notify['routes'] as $server => $settings){
33             if(empty($settings['domains']) || empty($settings['username']) || empty($settings['password'])){
34                 $error[] = "{$server} missing domains / username / password";
35                 continue;
36             }
37             
38             foreach ($settings['domains'] as $dom){
39 //                $mailer = Mail::factory('smtp', array(
40 //                    'host'    => $dom ,
41 //                    'localhost' => $server,
42 //                    'timeout' => 15,
43 //                    'auth' => true,
44 //                    'username' => $settings['username'],
45 //                    'password' => $settings['password']
46 //                ));
47 //                
48 //                print_R($mailer);exit;
49                 
50 //                $params = array(
51 //                    'netdns' => false
52 //                );
53                 
54 //                $smtpmx = new Mail_smtpmx($params);
55 //                $smtpmx->debug = true;
56                 
57                 $options = array(
58             'verify_peer'  => false,
59             'verify_peer_name'  => false,
60             'allow_self_signed' => true);
61                 
62                 $smtp = new Net_SMTP($server, 25, $dom, false, 0, $options);
63                 
64                 $smtp->setDebug(true);
65 //                print_R($smtp);
66                 
67 //                print_R($smtpmx->_smtp);exit;
68                 
69                 $res = $smtp->connect($smtpmx->timeout);
70                 
71                 if (is_a($res, 'PEAR_Error')) {
72                     print_R('error?????');exit;
73                 }
74                 
75                 $r = $smtp->auth($settings['username'], $settings['password']);
76             
77                 print_R($r);exit;
78 //                $smtpmx->_smtp->disconnect();
79                 print_r("resutlt : {$res} \n");
80                 exit;
81                     
82 //                $mx = $smtpmx->_getMx($dom);
83 //                
84 //                foreach ($mx as $mserver => $mpriority) {
85 //                    
86 //                    $smtpmx->_smtp = new Net_SMTP($mserver, $smtpmx->port, $smtpmx->mailname);
87 //                    
88 ////                    print_R($smtpmx);exit;
89 //                    $res = $smtpmx->_smtp->connect($smtpmx->timeout);
90 //
91 //                    $smtpmx->_smtp->disconnect();
92 //                    
93 //                    print_R($res);exit;
94 //                }
95                 
96             }
97             
98             
99         }
100     }
101     
102 }