【问题标题】:retrive the emails from my own server email address like manoj@manoj.com从我自己的服务器电子邮件地址中检索电子邮件,例如 manoj@manoj.com
【发布时间】:2015-01-20 13:24:55
【问题描述】:

是否可以从我自己的域邮件中获取电子邮件?我想获取收件箱,请帮忙,我现在正在使用 IMAP,但它给了我像

这样的 ssl 错误

MAIL.enlighten-energy.net 证书失败:服务器名称与证书不匹配:/OU=Domain Control Validated/OU=PositiveSSL Wildcard/CN=*.justhost.com

function fetch_gmail_inbox()
    {

        $res=array();
        /* connect to gmail */
        $hostname = '{imap.enlighten-energy.net:143/imap}';
        $username = 'abc@enlighten-energy.net';
        $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);



}

但它对我不起作用任何建议都会很明显。在此先感谢

【问题讨论】:

  • "不工作" = ?一些错误信息?
  • MAIL.enlighten-energy.net 的证书失败:服务器名称与证书不匹配:/OU=Domain Control Validated/OU=PositiveSSL Wildcard/CN=*.justhost.com
  • $hostname = '{mail.enlighten-energy.net:143/imap/novalidate-cert}INBOX';使用这个

标签: php server


【解决方案1】:

MAIL.enlighten-energy.net 证书失败:服务器名称与证书不匹配:/OU=Domain Control Validated/OU=PositiveSSL Wildcard/CN=*.justhost.com

如果你了解 SSL/TLS,错误信息其实很清楚:

  • 您访问imap.enlighten-energy.net(这是mail.enlighten-energy.net 的别名)
  • 但是服务器的证书是为*.justhost.com颁发的
  • 由于*.justhost.comimap.enlighten-energy.net 不匹配,因此它不会信任证书,因为如果它只信任任何证书,那么连接就会受到可以破坏加密的中间人攻击。

总而言之:如果您想为 IMAP 服务器使用您自己的域名,您必须使用您自己的域的证书来设置此服务器。如果这是多台主机之间的共享服务器,并且您无权访问此服务器的配置,则无法执行此操作。

【讨论】:

  • 那我该怎么办呢?请帮我解决这个问题,我用过“$hostname = '{MAIL.justhost.com:143}INBOX';”对于主机名,它显示错误“与 mail.justhost.com,143 的连接失败”
  • 我很确定您的托管服务提供商已经记录了您需要为 IMAP 服务器使用的主机名。
  • 我不明白您所说的“我如何检查那个主机名????”是什么意思。再次:与您的托管服务提供商确认您应该如何访问 IMAP 服务器,如果它是共享服务器,如果这是您自己的,请将其配置为使用正确的证书。
【解决方案2】:

找到解决方案,我必须使用

$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);



    }

【讨论】:

    猜你喜欢
    • 2017-08-29
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 2018-03-15
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多