php simulates GMAIL, HOTMAIL (MSN), YAHOO, 163, 126 email login (original)
I have been busy recently, and at the end of the National Day holiday, I published this article in order to make these source codes open source
br />
Of course these methods may not be advisable, but this should be the general direction, because we are currently building a UCHOME Hong Kong and Taiwan site
We plan to change the friend invitation I didn’t pay much attention to the display inside at first, so I just said OK!
When I did this, I discovered that this place in UCH was made using roaming mode, which was very confusing and nothing could be changed!
Alas, since I agreed and said it was OK, now the actual situation is no longer possible, so I feel embarrassed. In order to quickly solve this problem, I searched on GOOGLE and Baidu.
Once again, the result was unexpected again. There was only an open source example of 126 mailbox, and there was no other one. There was a brother who kept QQ and said he wanted other source codes.
You can add QQ to buy it! No more comments for this person! I spent some time and sorted it out, and luckily I got a few. Because time is limited, I have been working on the project at hand, so I didn’t care about the others. Now I give GMAIL, HOTMAIL (MSN), PHP source code of YAHOO’s email contact:
1.GMAIL
- PHP code
<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "COOKIE" ) ); //Define the path where COOKIES is stored, and you must have operating permissions
define( "TIMEOUT", 1000 ); //Timeout setting
class GMAIL
{private function login($username, $password)
{
//Step 1: Simulate grabbing the data of the login page and write down COOKIES
$COOKIES = array();
$matches = array();
//Get the form
$login_url = "https://www.google.com/accounts/ServiceLoginAuth";
$ch = curl_init($login_url);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$cOntents= curl_exec($ch);
curl_close($ch);//Simulation parameters
$name = array('dsh','timeStmp','secTok');
foreach($name as $v) {
preg_match('//i', $contents, $matches);
if(!empty($matches)) {
$$v = $matches[1];
$matches = array();
}
}
$server = 'mail';
preg_match('//i', $contents, $matches) ;
if(!empty($matches)) {
$GALX = $matches[1];
$matches = array();
}
$timeStmp = time();//Step 2: Start logging in
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth");
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_POST, 1);
$fileds = "dsh=$dsh&Email=".$username."&Passwd={$password}&GALX=$GALX&timeStmp=$timeStmp&secTok=$secTok&signIn=Sign in&rmShown=1&asts=&PersistentCOOKIE=yes";
curl_setopt($ch, CURLOPT_POSTFIELDS, $fileds);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$str = curl_exec($ch);
curl_close($ch);//The third step: check COOKIES is also a guide page
$ch = curl_init("https://www.google.com/accounts/CheckCOOKIE?chtml=LoginDoneHtml");curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
$str2 = curl_exec($ch);curl_close($ch);
if (strpos($contents, "Safe exit") !== false)
{
return FALSE;
}
return TURE;
}//Get email address book-address
public function getAddressList($username, $password)
{
if (!$this->login($username, $password))
{
return FALSE;
}
//Start progress��Simulated crawling
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mail.google.com/mail/contacts/data/contacts?thumb=true&groups=true&show=ALL&enums=true&psort=Name&max=300&out=js&rf=&jsx=true"); // out=js returns json data, if not set it returns xml data
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
/* This setting is required when returning xml data
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
$str = "";
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);*/
curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
$cOntents= curl_exec($ch);
curl_close($ch);
//die($contents);
//get mail list from the page information username && emailaddress
/* Processing when returning xml data
preg_match_all("/(.*)/Umsi",$contents,$mails);
preg_match_all("/(.*)/Umsi",$contents,$names);
$users = array();
foreach($names[1] as $k=>$user)
{
//$user = iconv($user,'utf-8','gb2312');
$users[$mails[1][$k]] = $user;
}
if (!$users)
{
return 'There is no contact in your mailbox yet';
}
*/
$cOntents= substr($contents, strlen('while (true); &&&START&&&'), -strlen('&&&END&&& '));
return $contents;
}
}$gamil = new GMAIL;
$res = $gamil->getAddressList('[email protected]','123456');
echo $res;
?>