אני מנסה לשלוף אימיילים מPOP3 בעזרת סוקטים אבל אני לא מצליח להתחבר לג'ימייל.
הינה הקוד:
PHP קוד:
<?
// mail server settings
$host="pop.gmail.com";
$port = 995;
$user = "username";
$pass = "password";
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
// if a handle is not returned
if (!$fp)
{
die("Error: could not open socket connection\n");
}
else
{
// get the welcome message
$welcome = fgets ($fp, 150);
// check for success code
if (substr($welcome, 0, 3) == "+OK")
{
// send username and read response
fputs ($fp, "USER $user\n");
fgets($fp, 50);
// send password and read response
fputs ($fp, "PASS $pass\n");
$ack = fgets($fp, 50);
// check for success code
if (substr($ack, 0, 3) == "+OK")
{
// send status request and read response
fputs ($fp, "STAT\n");
$status = fgets($fp, 50);
if (substr($status, 0, 3) == "+OK")
{
// shut down connection
fputs ($fp, "QUIT\n");
fclose ($fp);
}
// error getting status
else
{
die ("Server said: $status");
}
}
// auth failure
else
{
die ("Server said: $ack");
}
}
// bad welcome message
else
{
die ("Bad connection string\n");
}
// get status string
// split by spaces
$arr = explode(" ", $status);
// the second element contains the total number of messages
echo $arr[1] . " messages in mailbox";
}
?>
זה כל הזמן מגיע לחלק של הBad connection string
תודה לעוזרים.