Vector Posted October 24, 2012 Share Posted October 24, 2012 i actually have this working, all the way up to the handshake and the close of the connection. the problem is, it only works over telnet, and not with mail sent via sendmail nor gmail. here's the setup: # the script is running as a SERVICE on port 25, and i launched it from the terminal so i can see its echos (so i know what it's doing) # the firewall is open to the internet # i telnet into the public ip on port 25 via "telnet example.com 25", using another open terminal, and i can do a full smtp session, and view output in the client side, and view server side echos in the server's terminal # i use "sendmail -t user@example.com <n>blah blah!<n>.<n>" and sendmail seems to accept it, but the server side terminal does not respond in any way # i use gmail to send an email, and the server side terminal has no output so, i'm stumped as to why it APPEARS that mail transfer agents are not reaching my smtp service, and yet its just fine with telnet. it would output SOMETHING to show at least a connection was made, but i get nothing. here's a snippet of my code: <?// if ($socket = socket_create_listen(25)){ if ($socket = socket_create(AF_INET , SOCK_STREAM , SOL_TCP)){ //socket_set_option($socket , SOL_SOCKET , SO_REUSEADDR , 1); echo "TCP Socket Created\n"; if (socket_bind($socket , '0.0.0.0' , 25)){ echo "TCP Socket Bound\n"; socket_listen($socket); //socket_set_nonblock($socket); while(true){ if($connection = socket_accept($socket)){ echo "\n================================BEGIN================================\n"; ... } } }else{ echo "tcp Socket Failed to bind\n"; } }else{ echo "tcp Socket Failed to Create\n"; } thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/269846-php-smtp-server-for-receiving-incoming-mail/ Share on other sites More sharing options...
kicken Posted October 24, 2012 Share Posted October 24, 2012 Have you tried it via telnet from an external source, such as a VPS somewhere or an online port scanner? Many residential service ISP's block port 25 so if you're running this on that type of connection that may be your issue. If that's not the problem you'll have to provide some more details/code. On a different note, why are you trying to write a SMTP server using PHP when there are plenty of perfectly good servers already available? Quote Link to comment https://forums.phpfreaks.com/topic/269846-php-smtp-server-for-receiving-incoming-mail/#findComment-1387382 Share on other sites More sharing options...
Vector Posted October 24, 2012 Author Share Posted October 24, 2012 (edited) i wonder why i never got an email about a reply to this [o_0]. i did not have the chance to go elsewhere and test it, but that was on my todo list. as far as WHY i'm doing this when there's plenty of "good" servers out there: i don't like any of them. they're archaic, cumbersome, inflexible, esoteric, 3 generations behind where they SHOULD BE, etc. this is just a prototype. at some point i will learn c++ well enough to rewrite them in c++. i already prototyped a DNS server in php (that was not fun, but it works fast as ****). next after the mail server is going to be a web server. the world needs to be able to do more with their servers, and easier - we need tighter integration with each type of service - we've needed it for a long time... anyway, back to the problem at hand ... the problem was sendmail - or the lack therof. i had postfix installed, and stopped it from running so that i could play with my php mail server prototype. well, i forgot, there's "sendmail" the PACKAGE (linux), and then there's "sendmail" the POSTFIX wrapper module which emulates sendmail (so that you don't have to have sendmail running, which would interfere with postfix), and since posftix wasn't running, it wasn't SENDING. so, installing the sendmail package fixed that problem. the other problem still persists - where i still can't send a mail from the web. however, since it works locally, and my firewall is disabled, and my router's portforwarding is correct, i think it's safe to assume that's just a DNS error, which i'll take care of later. thanks for your time and assistance \m/ Edited October 24, 2012 by Vector Quote Link to comment https://forums.phpfreaks.com/topic/269846-php-smtp-server-for-receiving-incoming-mail/#findComment-1387407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.