网易邮箱登录php,PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法

本文实例讲述了PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法。分享给大家供大家参考。具体实现方法如下:

header("Content-Type: text/html; charset=UTF-8");

error_reporting(0);

/**

* 登陆

* $user 163用户名

* $pass 密码

**/

function login($user,$pass){

//登陆

$url = 'http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1';

$cookie = tempnam('./cache/','~');//创建一个用于存放cookie信息的临时文件

$fields_post = array(

'username'      => $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, true);

curl_setopt($ch, 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('');

}else{

$G_ROOT = dirname(__FILE__);

file_put_contents($G_ROOT.'/cache/cookie', $cookie);

return $cookie;

}

}

/**

*

* $data['url'] 请求地址

* $data['data_post'] post数据

* $data['cookie']

*

**/

function curl($data){

$url = $data['url'];

$data_post= $data['data_post']? $data['data_post']: false;

$cookie = $data['cookie'];

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

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);  //cookie文件 登陆之后

//POST 提交

if($data_post){

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_post);

}

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

希望本文所述对大家的php程序设计有所帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值