Home >Backend Development >PHP Tutorial >163.com email login php curl code to log in to 163 email and grab the email friend list (tested)
To put it bluntly, CURL technology simulates browser actions to achieve page crawling or form submission. Through this technology, many interesting functions can be achieved.
Copy the code The code is as follows:
error_reporting(0);
//Email user name (without @163.com suffix)
$user = 'papatata_test';
/ /Email password
$pass = '000000';
//Target email address
//$mail_addr = uenucom@163.com';
//Login
$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';
$ch = curl_init ($url);
//Create a temporary file to store cookie information
$cookie = tempnam('.','~');
$referer_login = 'http://mail.163.com';
//The return result is stored in a variable instead of the default direct output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, $referer_login);
$fields_post = array(
'username'=> $user,
'password'=> $pass,
'verifycookie '=>1,
'style'=>-1,
'product'=> 'mail163',
'selType'=>-1,
'secure'=>'on'
);
$headers_login = 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'
);
$fields_string = '';
foreach($fields_post as $key => $value)
{
$fields_string .= $key . '=' . $value . '&';
}
$fields_string = rtrim($fields_string , '&');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
//When closing the connection, save the cookie returned by the server as follows In the file, ucurl_Setopt ($ CH, CURLOPT_COOKIEJAR, $ Cookie);
CURL_SETOPT ($ ch, Curlopt_httpheader, $ headers_login); Rlopt_post, count ($ fields)); fields_string);
$result= curl_exec($ch);
curl_close($ch);
//Jump
$url='http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight= 1&verifycookie=1&language=-1&style=-1&username=loki_wuxi';
$ch = curl_init($url);
$headers = array(
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1 ; en-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECT TIMEOUT, 120 ; );
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//Get sid
preg_match('/sid=[^"].*/ ', $result, $location);
$sid = substr($location[0], 4, -1);
//file_put_contents('./result.txt', $sid);
//Address book address
$url='http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid='.$sid.'&gid=all';
$ch = curl_init($url);
$ headers = array(
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HT TPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//file_put_contents('./result .txt', $result);
unlink($cookie);
//Start crawling content
preg_match_all('/