Jump to content


Photo

Receive mail via sockets


  • Please log in to reply
No replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 20 August 2006 - 08:48 AM

Ok I am attempting to create a script that will accept in comming email. I thought that sockets would be the way to go.

This is what I have so far(this is an extreme beta verson)

<?php
$port = "25";

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket == false) {
    die("Error in createing the socket, the error code is " . socket_last_error() . " 
	    and the error message is " . socket_strerror(socket_last_error()));
}
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
    die("Unable to set socket option. The error is " . socket_last_error() . "
	     and the error message is " . socket_strerror(socket_last_error()));
}		 
$bind = socket_bind($socket, NULL, $port);

if ($bind == false) {
    socket_close($socket);
	die("socket_bind failed. The error code is " . socket_last_error() . "
	     and the error message is " . socket_strerror(socket_last_error()));
}
$listen = socket_listen($socket, SOMAXCONN);
if ($listen == false) {
    socket_close($socket);
    die("socket_listen failed. The error code is " . socket_last_error() ."
	     and the error message is " . socket_strerror(socket_last_error()));
}
socket_accept($socket);
while (socket_recv($socket, $mail, 77, 2)) {
    echo "$mail";
}
usleep(10000);
echo "This test worked and we are listening on port $port";
socket_close($socket);		 
?>

All this does is listen to port 25.

My first question is how can I have this script  continuously listening to the port?

Should I use
socket_read()
instead of accept?

Any suggestions would be great.

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users