Jump to content

Receive mail via sockets


tomfmason

Recommended Posts

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)

[code]
<?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);
?>[/code]

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 [code=php:0]socket_read()[/code] instead of accept?

Any suggestions would be great.

Thanks,
Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.