本文实例讲述了PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法。分享给大家供大家参考。具体实现方法如下:
代码如下:
$user,
'password' => $pass,
'verifycookie' => 1,
'style' => -1,
'product' => 'mail163',
'selType' => -1,
'secure' => 'on'
);
$fields_string = '';
foreach($fields_post as $key => $value){
$fields_string .= $key . '=' . $value . '&';
}
$fields_string = rtrim($fields_string,'&');
$headers = array(
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',
'Referer' => 'http://www.163.com'
);
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//返回结果存放在变量中,而不是默认的直接输出
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);//关闭连接时,将服务器端返回的cookie保存在以下文件中
curl_setopt($ch,CURLOPT_POST,CURLOPT_POSTFIELDS,$fields_string);
$result= curl_exec($ch);
curl_close($ch);
preg_match_all('/
/i',$result,$infos,PREG_SET_ORDER);
if(!empty($infos['0']['1'])){
unlink($cookie);
exit('