ocpaul20 Posted February 25, 2010 Share Posted February 25, 2010 On a linux machine, I want to run a php program which loops looking for anything coming in on a particular port. In this case it is port 25, the smtp port of mail. I have no mail server running. I have written a php program using sockets which does this and I have written another program to send it stuff. Classic client -> server idea. Both work and communicate with each other run as cgi in 2 terminal windows. My problem is that when I run a program from my browser which calls the mail() function, it returns false. this is the program I run from a browser which I want to connect to another program running in a terminal window looking for input from port 25. error_reporting(E_ALL); ini_set("SMTP","/root/httpd/localhost/httpdocs/dummy_smtp_server.php"); // run as a cgi in a terminal window ini_set("smtp_port","25"); $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $m = mail($to, $subject, $message, $headers); echo "<br>returned from mail: "; var_dump($m); in my php.ini file I have this [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. sendmail_from = me@localhost.com ; For Unix only. sendmail_path = "/root/httpd/localhost/httpdocs/dummy_smtp_server.php" So, my question is - does anyone have any idea what I can do to get this working please or why it doesn't work? Thanks Paul Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 25, 2010 Share Posted February 25, 2010 telnet localhost 25 is this open in ur machine.. if open then it will work.. Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted February 25, 2010 Author Share Posted February 25, 2010 I have already said that I can run another terminal and communicate with the port 25 server. running telnet localhost 25 in a terminal does communicate successfully with the server program running in another console. It is the mail() function that I am having trouble running in a php program (shown above) from the browser. It will not connect/send mail to a server program running in a console watching for incoming characters on port 25. Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted March 14, 2010 Author Share Posted March 14, 2010 any more ideas please anyone? It would really help if I had a mickey mouse program like this that I could call using mail() from my application that just sat in the background and accepted mails and then responded with the correct code to make the application think the mail had been sent. Surely someone has played with sockets and was able to do this kind of thing? The programming part is not hard, but the way to get it to work on a unix machine that is beating me. Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted March 14, 2010 Author Share Posted March 14, 2010 OK, well I have found the solution and it is that the mail() statement sends to whatever is in the php.ini file variiable sendmail_path = "/opt/lampp/bin/php -f /root/httpd/utils/httpdocs/trapmail.php -c /usr/httpd" I put this and wrote the program trapmail.php. The email comes in in stdin so you need to read that to get the output from mail(). You also need to return 0; at the end to say to mail() that it was successful. $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); It seems that there are lots of examples of this on the internet, so I read a few articles and got it sorted. Quote Link to comment 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.