2014-11-22 82 views
1

是否可以從我自己的域郵件中獲取電子郵件?我想獲取收件箱,請爲此提供幫助,我現在正在使用IMAP,但它給我的SSL錯誤,如從我自己的服務器電子郵件地址中檢索電子郵件,例如[email protected]

MAIL.enlighten-energy.net證書失敗:服務器名稱不符合證書:/ OU =域控制驗證/ OU = PositiveSSL通配符/ CN = *。justhost.com

function fetch_gmail_inbox() 
    { 

     $res=array(); 
     /* connect to gmail */ 
     $hostname = '{imap.enlighten-energy.net:143/imap}'; 
     $username = '[email protected]'; 
     $password = '*******'; 

     /* try to connect */ 
     $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 

     /* grab emails */ 
     $emails = imap_search($inbox,'UNSEEN'); 

     /* if emails are returned, cycle through each... */ 
     if($emails) { 

      /* put the newest emails on top */ 
      rsort($emails); 

      /* for every email... */ 
      foreach($emails as $email_number) { 

       /* get information specific to this email */ 
       $overview = imap_fetch_overview($inbox,$email_number,0); 
       $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1)); 
       $structure = imap_fetchstructure($inbox,$email_number); 
       if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3) 
       { 
        $message=imap_base64($message); 

       } 
       if($structure->parts[0]->encoding == 4 ||$structure->encoding == 4) 
       { 
        $message = imap_qprint($message); 
       } 
       $message2= quoted_printable_decode(imap_fetchbody($inbox,$email_number,0)); 
       $date=explode(':',$message2); 
       $date2= date('d-m-Y h:i:s',strtotime($date[8].':00:00')); 


       if($overview[0]->subject=="USR:Site01_Comms Complete") 
       { 
        $res['date']=$date2; 
        $res['body']=$message; 
       }else 
       { 
        echo "not a correct mail"; 
       } 
      } 

      return $res; 
    } 

    /* close the connection */ 
    imap_close($inbox); 



} 

但它不是爲我工作的任何建議,將明顯的.thanks提前

+0

「不工作」=?一些錯誤信息? – ethrbunny 2014-11-22 13:11:08

+0

MAIL.enlighten-energy.net證書失敗:服務器名稱與證書不匹配:/ OU =域控制驗證/ OU =正面SSL通配符/ CN = *。justhost.com – john 2014-11-22 13:16:19

+1

$ hostname ='{mail.enlighten-energy。淨:143/IMAP/NOVALIDATE證書} INBOX';使用這個 – 2015-01-29 07:31:23

回答

0

找到了解決辦法,我必須使用

$hostname = '{mail.enlighten-energy.net:143/imap/novalidate-cert}INBOX'; 

,而不是這個

$hostname = '{imap.enlighten-energy.net:143/imap}'; 

一樣,這裏是完整的解決方案

function fetch_gmail_inbox() 
    { 

     $res=array(); 
     /* connect to gmail */ 
     $hostname = '{mail.enlighten-energy.net:143/imap/novalidate-cert}INBOX'; 
     $username = Yii::app()->getModule('user')->get_config('datalogger_email'); 
     $password = Yii::app()->getModule('user')->get_config('datalogger_email_pwd'); 

     /* try to connect */ 
     $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 

     /* grab emails */ 
     $emails = imap_search($inbox,'UNSEEN'); 
     /* if emails are returned, cycle through each... */ 
     if($emails) { 

      /* put the newest emails on top */ 
      rsort($emails); 

      /* for every email... */ 
      foreach($emails as $email_number) { 

       /* get information specific to this email */ 
       $overview = imap_fetch_overview($inbox,$email_number,0); 
       $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1)); 
       $structure = imap_fetchstructure($inbox,$email_number); 
       if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3) 
       { 
        $message=imap_base64($message); 

       } 
       if($structure->parts[0]->encoding == 4 ||$structure->encoding == 4) 
       { 
        $message = imap_qprint($message); 
       } 
       $message2= quoted_printable_decode(imap_fetchbody($inbox,$email_number,0)); 
       $date=explode(':',$message2); 
       $date2= date('d-m-Y h:i:s',strtotime($date[8].':00:00')); 


       if($overview[0]->subject=="USR:Site01_Comms Complete") 
       { 
        $res['date']=$date2; 
        $res['body']=$message; 
       } 
      } 

      return $res; 
     } 

     /* close the connection */ 
     imap_close($inbox); 



    } 
1

證書失敗的郵件。 enlighten-energy.net:服務器名稱與證書不符:/ OU =域控制驗證/ OU = PositiveS SL通配符/ CN = * justhost.com

錯誤消息其實是很清楚,如果你理解SSL/TLS:

  • 您訪問imap.enlighten-energy.net(這是一個CNAME到mail.enlighten-energy.net
  • 但服務器的證書頒發給*.justhost.com
  • 由於*.justhost.com不符合imap.enlighten-energy.net它不會信任證書,因爲如果它只信任任何證書,那麼連接將對man-i開放可以打敗加密的中間攻擊。

總結:如果你想使用你自己的域名作爲IMAP服務器,你必須爲你自己的域設置一個證書。如果這是多個主機之間的共享服務器,並且您無權訪問此服務器的配置,則無法執行此操作。

+0

所以我該怎麼做呢?請幫我理清這一點,我用「$ hostname ='{MAIL.justhost.com:143}INBOX';'對於主機名不是它顯示錯誤「連接失敗mail.justhost.com,143」 – john 2014-11-24 06:35:13

+0

我很確定您的託管服務提供商已經記錄了您需要爲IMAP服務器使用哪個主機名。 – 2014-11-24 07:08:29

+0

我如何檢查主機名? – john 2014-11-24 07:12:12

相關問題