title: Login to gmail from my site
body: <p>There are lot of similar questions, but none of them answered properly.</p>
  
  <p>Issue : I have gmail username(email id) and password, I want to login to gmail with out redirecting the page to gmail.com</p>
  
  <p>I tried :</p>
  
  <p>a. Fetched the source code (View source from browser), and copied it in a html page,
      onload I added username and password to this form and submitted this page with javascript
      => It works fine.</p>
  
  <pre><code>But, I need to fetch the source dynamically, using PHP.
  
  So, I tried with `file_get_contents` =&gt; Here I am not able to get full source code some of the js code and some hidden fields are missing =&gt; When I tired to login with this code, it is not logging in, it simply redirects to gmail.com login page.
  
  Then I tried to get the source code using cURL, This also gave me incomplete source, and I am not able to login.
  </code></pre>
  
  <p>b. I tried to login using cURL.</p>
  
  <p>I was able to get the gmail feed using following code.</p>
  
  <pre><code>$email    = 'username@gmail.com';
  $password = 'password';
  $curl     = curl_init('https://mail.google.com/mail/feed/atom');
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_USERPWD, $email.':'.$password);
  echo $content  = curl_exec($curl);
  </code></pre>
  
  <p>But, When tired the code to login to <code>https://accounts.google.com/ServiceLogin</code> it is not loging in.</p>
  
  <pre><code>$email    = 'username@gmail.com';
  $password = 'password';
  $curl     = curl_init('https://accounts.google.com/ServiceLogin');
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_USERPWD, $email.':'.$password);
  echo $content  = curl_exec($curl);
  </code></pre>
  
  <p>Question : 1. Is it possible to login to gmail, from mysite ?</p>
  
  <blockquote>
    <p>I don't want to use open ID - Here I need to enter username and password again. My username and password in already stored in DB (I know this is not secure.). So my requirement is while clicking a link automatically login to gmail.</p>
  </blockquote>
  
  <p>Question : 2. Is it possible to take take the complete (Which we can see in browser "view source") source code of gmail(Login page of gmail), either using php or javascript or jQuery ?</p>