note 48373 added to function.fsockopen

From: Date: Tue, 21 Dec 2004 09:26:55 +0000
Subject: note 48373 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-82117@lists.php.net to get a copy of this message
[php] <?php /* $handle = smtp_connect($smtp_server, 25, 30, 1, 1, 1); echo smtp_command($handle, "EHLO $domain\r\n", 1, 1); echo smtp_command($handle, "MAIL FROM:<$from_mail>\r\n", 1, 1); echo smtp_command($handle, "RCPT TO:<$to_mail>\r\n", 1, 1); echo smtp_command($handle, "DATA\r\n", 1, 1); echo smtp_command($handle, "$message\r\n.\r\n", 1, 1); // don't do it like this - it will hang up // echo smtp_command($handle, "$message", 1, 1); // echo smtp_command($handle, "\r\n.\r\n", 1, 1); echo smtp_command($handle, "QUIT\r\n", 1, 1); smtp_close($handle); */ function smtp_connect($host, $port, $timeout=30, $echo_command=False, $echo_response=False, $nl2br=False) { $errno = 0; $errstr = 0; if($echo_command) { if($nl2br) { echo nl2br("CONNECTING TO $host\r\n"); } else { echo "CONNECTING TO $host\r\n"; } } $handle = fsockopen($host, $port, $errno, $errstr, $timeout); if(!$handle) { if($echo_command) { if($nl2br) { echo nl2br("CONNECTION FAILED\r\n"); } else { echo "CONNECTION FAILED\r\n"; } } return False; } if($echo_command) { if($nl2br) { echo nl2br("SUCCESS\r\n"); } else { echo "SUCCESS\r\n"; } } $response = fgets($handle,1); $bytes_left = socket_get_status($handle); if ($bytes_left > 0) { $response .= fread($handle, $bytes_left["unread_bytes"]); } if($echo_response) { if($nl2br) { echo nl2br($response); } else { echo $response; } } return $handle; } function smtp_command($handle, $command, $echo_command=False, $nl2br=False) { if($echo_command) { if($nl2br) { echo nl2br($command); } else { echo $command; } } fputs($handle, $command); $response = fgets($handle,1); $bytes_left = socket_get_status($handle); if ($bytes_left > 0) { $response .= fread($handle, $bytes_left["unread_bytes"]); } if($nl2br) { return nl2br($response); } else { return $response; } } function smtp_close($handle) { fclose($handle); } ?>[/php] as posted by termanal can be used on 100webhost when you don't have a domain as mail() does'nt work ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48373 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48373&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48373&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82117) next »