php3-list | 199807
Date: 07/14/98
- Next message: Michael J. Miller Jr.: "Re: [PHP3] What am I doing wrong here?"
- Previous message: Jinsoo Hwang: "[PHP3] ImageString16 and ImageStringUp16 ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Heres a very simple rough program which talks to an SMTP server and gets
info from it. Take a look at the structure of the requests to the SMTP
server and how the script looks for the '-' symbol which signifies the end
of the smtp's response to a command.
The script does the following
1. Checks the Server to see if it exisits.
2. Connects to the server prints the servers reply to the connect.
3. Sends the HELP command.
4. Reads in the reply until it sees a 214 without a '-' after it. (this
signals the end of the response.)
5. Runs a VRFY command.
etc............
> Well, you're probably getting tired of hearing from me, but I still cannot
> retrieve any information beyond the first line of the socket connection.
> Here's a copy of my code:
----------------------------------------------------------------------------
--- <html> <head> <title>Email Address Verification</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head><body bgcolor="#FFFFFF"> <h3>Email Address Verification Form</h3> <form method="post" action="socket.php3"> Username: <input type="text" name="username" size="30" value="<? echo $username;?>" maxlength="30"><BR> Server: <input type="text" name="server" size="30" value="<? echo $server;?>" maxlength="50"> <input type="submit" name="submit" value="Verify Address"><BR> </form> <HR> <?
if($submit){
$ip = gethostbyname($server); echo "IP number for ".$server." is ".$ip."<BR><BR>"; // SMTP COMMAND SECTION OF THE EMAIL ADDRESS VERIFICATION SCRIPT // $fp = fsockopen($server,25,&$errno, &$errstr); if(!$fp) { echo "<BR>Error in connection - ".$errstr." (".$errno.")<br>\n"; } else { set_socket_blocking($fp,0);
$response = fgets($fp,512); echo $response."<BR>"; if (ereg("(220)", $response, $regs)){ $valid = 1; } else { echo "Incorrect Login<BR>" ; exit; } echo "<BR><BR><B>Running Help Command</B><BR>"; fputs($fp,"help ".chr(13).chr(10)); $response="214-"; while (ereg("(214-)",$response)) { $response = fgets($fp,512); echo $response."<BR>"; }
echo "<BR><BR><B>Running Verify Command</B><BR>"; fputs($fp,"vrfy ".$username.chr(13).chr(10)); $response = fgets($fp,512); echo "<TEXTAREA>".$response."</TEXTAREA>"; if (!(ereg("(250)",$response))){ fputs($fp,"vrfy postmaster".chr(13).chr(10)); $response = fgets($fp,512); echo "<BR><B>Postmaster's Address</B><BR><TEXTAREA>".$response."</TEXTAREA>"; }elseif (!(ereg("(250)",$response))){ fputs($fp,"vrfy hostmaster".chr(13).chr(10)); $response = fgets($fp,512); echo "<BR><B>Hostmaster's Address</B><BR><TEXTAREA>".$response."</TEXTAREA>"; } fclose($fp);
// FINGER COMMAND SECTION OF THE EMAIL ADDRESS VERIFICATION SCRIPT // echo "<BR><BR><B>Running Finger Command</B><BR>"; $fp = fsockopen($server,79,&$errno, &$errstr); if(!$fp) { echo "<BR>Error in Finger Connection - ".$errstr." (".$errno.")<br>\n"; } else { fputs($fp,$username.chr(13).chr(10)); while (!feof($fp)) { echo "<TEXTAREA>".fgets($fp,127)."</TEXTAREA><BR>"; } fclose($fp); } }
}
?> </body> </html> <html> <head> <title>Email Address Verification</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
<body bgcolor="#FFFFFF"> <h3>Email Address Verification Form</h3> <form method="post" action="socket.php3"> Username: <input type="text" name="username" size="30" value="<? echo $username;?>" maxlength="30"><BR> Server: <input type="text" name="server" size="30" value="<? echo $server;?>" maxlength="50"> <input type="submit" name="submit" value="Verify Address"><BR> </form> <HR> <?
if($submit){
$ip = gethostbyname($server); echo "IP number for ".$server." is ".$ip."<BR><BR>"; // SMTP COMMAND SECTION OF THE EMAIL ADDRESS VERIFICATION SCRIPT // $fp = fsockopen($server,25,&$errno, &$errstr); if(!$fp) { echo "<BR>Error in connection - ".$errstr." (".$errno.")<br>\n"; } else { set_socket_blocking($fp,0);
$response = fgets($fp,512); echo $response."<BR>"; if (ereg("(220)", $response, $regs)){ $valid = 1; } else { echo "Incorrect Login<BR>" ; exit; } echo "<BR><BR><B>Running Help Command</B><BR>"; fputs($fp,"help ".chr(13).chr(10)); $response="214-"; while (ereg("(214-)",$response)) { $response = fgets($fp,512); echo $response."<BR>"; }
echo "<BR><BR><B>Running Verify Command</B><BR>"; fputs($fp,"vrfy ".$username.chr(13).chr(10)); $response = fgets($fp,512); echo "<TEXTAREA>".$response."</TEXTAREA>"; if (!(ereg("(250)",$response))){ fputs($fp,"vrfy postmaster".chr(13).chr(10)); $response = fgets($fp,512); echo "<BR><B>Postmaster's Address</B><BR><TEXTAREA>".$response."</TEXTAREA>"; }elseif (!(ereg("(250)",$response))){ fputs($fp,"vrfy hostmaster".chr(13).chr(10)); $response = fgets($fp,512); echo "<BR><B>Hostmaster's Address</B><BR><TEXTAREA>".$response."</TEXTAREA>"; } fclose($fp);
// FINGER COMMAND SECTION OF THE EMAIL ADDRESS VERIFICATION SCRIPT // echo "<BR><BR><B>Running Finger Command</B><BR>"; $fp = fsockopen($server,79,&$errno, &$errstr); if(!$fp) { echo "<BR>Error in Finger Connection - ".$errstr." (".$errno.")<br>\n"; } else { fputs($fp,$username.chr(13).chr(10)); while (!feof($fp)) { echo "<TEXTAREA>".fgets($fp,127)."</TEXTAREA><BR>"; } fclose($fp); } } } ?> </body> </html>
************************************************************************* Cameron Just (ccjust <email protected>)
Web Development Prentice Centre.
*************************************************************************
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.tryc.on.ca/php3.html
- Next message: Michael J. Miller Jr.: "Re: [PHP3] What am I doing wrong here?"
- Previous message: Jinsoo Hwang: "[PHP3] ImageString16 and ImageStringUp16 ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

