Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

POP before SMTP

35 views
Skip to first unread message

Pedro

unread,
Sep 22, 2003, 7:15:52 PM9/22/03
to
Hi all,

a friend using Windows wanted to send mail, but he got timeout errors
after editing php.ini Mail section

smtp = smtp.server.com
sendmail_from = fri...@server.com

I realized that was because of the need to "POP before SMTP",
so I made him a function. It's working ... for his server (and
hopefully other servers too).

Can this function be improved?
Is it ok to fsockopen in blocking mode?
What about timeout values?

Any hints to make this a more reliable function will be greatly
appreciated.


Here it is, hope it suits more Windows people without a mail server
and the need to POP before SMTP


<?php
function POP_authenticate($username, $password, $server) {
$socket = fsockopen($server, 110); // POP3 port
if (!$socket) {
return "Couldn't connect to $server:110\r\n";
}

$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res; // return the error
}
fputs($socket, "USER $username\r\n"); // send user
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "PASS $password\r\n"); // send pass
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "QUIT\r\n"); // quit

### I don't care for errors after quitting :-)

fclose($socket);
return false;
}
?>

and this is an example on how you can use it:

<?php
$username = "netuser";
$password = "pAzw04D";
$POPserver = "pop.server.com";
### php.ini's SMTP must correspond to this server
### and sendmail_from must be from this server (??)

$msg = POP_authenticate($username, $password, $POPserver);
if ($msg === FALSE) {
mail("som...@somewhere.com", "PHP test", "Line 1\nLine 2");
$msg = "mail (probably) sent.\r\n";
}
exit($msg);
?>


Comments? Suggestions? Corrections?
All are very welcome.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.

Yves Brault

unread,
Sep 26, 2003, 9:06:42 PM9/26/03
to
I think your function is pretty well done.


"Pedro" <hex...@hotpop.com> wrote in message
news:ieuumvgbd9ppvejcj...@4ax.com...

0 new messages