使用PHP cURL

时间:2016-07-03 18:08:34

标签: php curl hotmail

我正在尝试使用php和curl从实时邮件服务器获得完整的答案。我尝试连接pop3协议,但它无法正常工作。

代码清单1:

<?php 
    // create curl resource 
    $curl = curl_init(); 

    if($curl) {
        /* Set username and password */ 
        curl_setopt($curl, CURLOPT_USERNAME, "example@outlook.com");
        curl_setopt($curl, CURLOPT_PASSWORD, "password");

        curl_setopt($curl, CURLOPT_URL, "pop3://pop3.live.com");
        curl_setopt($curl, CURLOPT_PORT, 995);

        curl_setopt($curl, CURLOPT_USE_SSL,CURLUSESSL_ALL);

        curl_setopt($curl, CURLOPT_CAINFO, "./certificate.pem");

        curl_setopt($curl, CURLOPT_VERBOSE, true);

        //return the transfer as a string 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

        // $output contains the output string 
        $output = curl_exec($curl);
    }

    echo $output;

    curl_close($curl); 
?>

当我使用此代码时(使用 pop3 协议)。标准输出告诉我客户端在端口995上成功连接。但是无法读取响应。

  

响应阅读失败

     

关闭连接0

但是当我使用 https 协议而不是 pop3 (在相同的代码上)时,我得到了部分回复。它看起来像整个响应头,至少它看起来像它,因为它在最后一个文本后输出两个新行。

  

接受:* / *

1 个答案:

答案 0 :(得分:1)

cURL为安全POP over SSL提供了不同的协议标识符。

而不是pop3://尝试pop3s://而你应该得到回复。

* Rebuilt URL to: pop3s://pop3.live.com/
* Hostname was NOT found in DNS cache
*   Trying 134.170.170.231...
* Connected to pop3.live.com (134.170.170.231) port 995 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES256-SHA
* Server certificate:
*    subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; CN=*.hotmail.com
*    start date: 2015-12-15 22:26:11 GMT
*    expire date: 2016-12-15 22:26:11 GMT
*    subjectAltName: pop3.live.com matched
*    issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Organization Validation CA - SHA256 - G2
*    SSL certificate verify ok.
< +OK DUB006-POP162 POP3 server ready
> CAPA
< -ERR unrecognized command
> USER me@xxx
< +OK password required
> PASS pass
< +OK Logged in.
> LIST
< +OK 5226 messages:
string(59927) "1 1830
2 69432
3 2751
4 2726
5 18506
6 2868
7 4636
8 1955
9 2242
10 3697