我收到許多內容相同的電子郵件,例如PHP:獲取需要驗證的遠程網頁的內容?
Name: XXX
Phone: XXX
Bio: XXX
......
我想編寫一個PHP腳本來解析這些電子郵件並將數據保存到數據庫中。我試圖使用file_get_contents()來獲取這些電子郵件的內容。
問題是,它需要身份驗證才能訪問我的電子郵件。即使我已登錄到服務器上的電子郵件帳戶(實際上是localhost),file_get_contents()仍會返回提示我登錄的網頁。
那麼如何使用PHP腳本訪問我的電子郵件內容?
編輯:它是一個gmail帳戶。
以下代碼不起作用。
$login_url = 'https://www.google.com/accounts/ServiceLoginAuth';
$gmail_url = 'https://mail.google.com/';
$cookie_file = dirname(__FILE__) . '/cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_URL, $gmail_url);
// not sure how to set this option
curl_setopt($ch, CURLOPT_REFERER, $login_url);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
是的,這是HTTPS protocal。 openssl擴展已經啓用。 – powerboy 2010-05-16 06:59:52
@powerboy:你在使用IIS服務器嗎? – Sarfraz 2010-05-16 07:14:31
@Sarfraz:不,它是windows上的apache – powerboy 2010-05-16 07:15:56