121
Chapter 7 — Gmail Libraries
Then you set the setLoginInfo method, giving the username, password, and
time zone from GMT:
$gm->setLoginInfo($name, $pwd, $tz);
Finally, you tell Gmailer to connect:
$gm->connect();
You need to use setLoginInfo only once — Gmailer saves your Gmail cookies,
so once you’ve logged in, you only need to use the connect() method to pass
more commands.
Putting that all together, then, you arrive at Listing 7-1, which gets you logged in
to Gmail, ready for some more code.
Listing 7-1: Logging in to Gmail with PHP
require(“libgmailer.php”);
$gm = new GMailer();
$name = “username”;
$pwd = “password”;
$tz = “0”;
$gm->setLoginInfo($name, $pwd, $tz);
if ($gm->connect()) {
/** THE REST OF YOUR CODE GOES IN HERE **/
}
$gm->disconnect();
?>
The disconnect() method logs you out again.
Retrieving the Inbox
Once you are logged in, retrieving a thread is simple and is a good example to
show the deeper functions available from the Gmailer library.
Précédent

- 145/310

Suivant