Question

There's tons of info on logging in to Gmail and displaying the inbox and getting contacts etc, but I cannot figure out how to get the email itself into a variable so I can do stuff with it in PHP.

Here's what I have:

function inbox($username, $password){ 
    $url = "https://mail.google.com/mail/feed/atom"; 
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_ENCODING, "");
    $curlData = curl_exec($curl);
    curl_close($curl);
    return $curlData;
}
//calling the function
$em = "email@gmail.com";
$pw = "pass";
$feed = inbox($em, $pw);
    $x = new SimpleXmlElement($feed);
    echo "<ul>";
        foreach($x->entry as $msg){
            //extracting the link to the message from xml
            $href = $msg->link->attributes()->href;
            //create a link to the message and display title, summary    
            echo "<li><a href=\"".$href."\">".$msg->title."</a><br />".$msg->summary."</li>";
        }
    echo "</ul>";

Now when I click on the link I just created it just opens the message in gmail. I want to access the html of the message in a string/variable. I've tried all kinds of things. I've tried forwarding the message link to another page to open in curl but instead of showing me the message google sends some html with yet another link to the message. If the link is clicked in the browser it again, opens in gmail, but if I try to curl a third time to this link it shows me a blank page.

The point is, my work server doesn't have imap/pop enabled and cURL is the last think I know of that can accomplish this.

Was it helpful?

Solution

I ended up using imap remotely then cURLing it back to the server in question. I've determined that gmail doesn't allow messages to be sent via cURL, it's one of those google things, like where they don't allow frames, etc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top