Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fun with ports 3

Status
Not open for further replies.

peacecodotnet

Programmer
Joined
May 17, 2004
Messages
123
Location
US
I like to fool around with PHP on my server, and I'm trying to connect to the mail port of my server (port 25). The code that I have is as follows:

Code:
<?php
$fp = fsockopen("[URL unfurl="true"]www.mywebsite.com",[/URL] 25, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "MAIL FROM: bla@bla.com.com\r";
   $out .= "RCPT TO: me@mywebsite.com\r";
   $out .= "DATA\r";
   $out .= "Testing 1 2 3\r";
   $out .= ".\r";

   fwrite($fp, $out);

   fclose($fp);
}
?>

This should send me an email at me@mywebsite.com, and the from address should be bla@bla.com.

However, when I run this, it gives me an error that the connection was refused. How do I fix this?

Thanks in advance!

Peace out,
Peace Co.
 
Can you post the exact error message and socket error number please
 
the socket number appears to be 25 , ie sendmail.

If sendmail isn't configured to accept or relay mail from your domain, then this will fail. more recent versions ofsendmail have alot of spam controls to ensure that mail servers arent abused. ISP's and hosting providers do their best to ensure that mail servers willnot act as open relays or spam gateways.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
edit SMTP :-)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
have you tried to telnet to port 25 on windows open a cmd prpmpt and type telnet 25 and see what happens.
Freeserver in the uk do not allow you to use any one elses SMTP serve. so if you have a domain e.g fred.co.uk you might expect to config your email to use something like smtp.fred.co.uk you would actually use freserve.co.uk
 
Also, you have to be totally correct on how your O/S sends carriage returns and line feeds, the age old question, is it \r\l , \r , \n ......

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
OK, Just cos I was relly bored:

Things to note, SMTP will not accept commands untill it has issued a repsonse to the previous command.

Some SMTP servers require the use of HELO yourdomain.com to accept a connection (spam traceability + header)

Code:
<?php
$fp = fsockopen("192.168.7.1", 25, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
	
	$out="HELO somewhere.com\r\n"; // not always used, some servers require it
	$out1 = "MAIL FROM: bla@somewhere.com\r\n";
	$out2 = "RCPT TO: you@there.com\r\n";
	$out3 = "DATA\r\n";
	$out4 = "Testing 1 2 3\r\n";
	$out5 = ".\r\n";
	$out6 = "QUIT\r\n";



	fwrite($fp, $out);
	sleep(2);
	fwrite($fp, $out1);
	sleep(2);
	fwrite($fp, $out2);
	sleep(2);
	fwrite($fp, $out3);
	sleep(2);
	fwrite($fp, $out4);
  	sleep(2);
	fwrite($fp, $out5);
	sleep(2);
	fwrite($fp, $out6);
	sleep(2);
   fclose($fp);
}
?>

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
To answer Ingres, the error number is 111 and yes, I have done it with the windows telnet and it works.

Peace out,
Peace Co.
 
peacecodotnet:
Perhaps its a network issue.

You're originally posted code listed " as the target parameter of the fsockopen() function. Does the domain name you're using resolve to an address actually bound to your server, or is some kind of NAT taking place?

If it's the latter, the routing at the device performing the NATting will prevent packets from going from your machine, through the router, and back to your machine.

Are you running this script on the same machine on which your sendmail server is running? You might try "localhost" or the non-routeable address actually bound to the NIC.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top