|
Posted by comp.lang.php on 11/10/06 22:59
I came up with functions that I thought would do the trick:
[PHP]
if (!function_exists('smtp_close')) {
/**
* This function will close a socket resource handle
*
* Original function found at {@link
http://us3.php.net/manual/en/function.fsockopen.php#36819} Modified by
Phil Powell on 11/10/2006
*
* @access public
* @param resource $handle (reference) Make it a reference to ensure
single closure
*/
function &smtp_close(&$handle) {
fclose($handle);
}
}
if (!function_exists('smtp_command')) {
/**
* This function will return a response from an existing socket
connection via {@link smtp_connect}
*
* Original function found at {@link
http://us3.php.net/manual/en/function.fsockopen.php#36819} Modified by
Phil Powell on 11/10/2006
*
* @access public
* @param resource $handle
* @param string $command
* @param string $echoKommand (optional) Used to send back an echo
command to stdout
* @param string $nl2br (optional) Used to insert an optional break
line
* @return string $response
*/
function smtp_command($handle, $command, $echo_command = '', $nl2br
= '') {
if ($echo_command && $nl2br) echo nl2br($command); elseif
($echo_command) echo $command;
fputs($handle, $command);
$response = fgets($handle, 1);
$bytesLeft = socket_get_status($handle);
if ($bytesLeft > 0) $response .= fread($handle,
$bytesLeft['unread_bytes']);
if ($nl2br) return nl2br($response); else return $response;
}
}
if (!function_exists('smtp_connect')) {
/**
* This function will return a socket resource handle while attempting
to make an SMTP mail server connection
*
* Original function found at {@link
http://us3.php.net/manual/en/function.fsockopen.php#36819} Modified by
Phil Powell on 11/10/2006
*
* @access public
* @param string $host
* @param int $port (default 25)
* @param int $timeout (default 30)
* @param string $echoKommand (optional) Used to send back an echo
command to stdout
* @param string $echoResponse (optional) Used to send back an echo
response to stdout
* @param string $nl2br (optional) Used to insert an optional break
line
* @return resource $handle
*/
function smtp_connect($host, $port = 25, $timeout = 30, $echoKommand
= '', $echoResponse = '', $nl2br = '') {
$errno = $errstr = 0;
if ($echoKommand && $nl2br) echo nl2br("CONNECTING TO
$host\r\n"); elseif ($echoKommand) echo "CONNECTING TO $host\r\n";
$handle = fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$handle) {
if ($echoKommand && $nl2br) echo nl2br("CONNECTION
FAILED\r\n"); elseif ($echoKommand) echo "CONNECTION FAILED\r\n";
return false;
}
if ($echoKommand && $nl2br) echo nl2br("SUCCESS\r\n"); elseif
($echoKommand) echo "SUCCESS\r\n";
$response = fgets($handle, 1);
$bytesLeft = socket_get_status($handle);
if ($bytesLeft > 0) $response .= @fread($handle,
$bytesLeft['unread_bytes']);
if ($echoResponse && $nl2br) echo nl2br($response); elseif
($echoResponse) echo $response;
return $handle;
}
}
if (!function_exists('checkbounceback')) {
/**
* Check for mail server bounceback to ensure that submitted email
address actually exists
*
* @access public
* @param string $domain SMTP email domain name
* @param string $from Recipient email address
* @param string $to Sender email address
* @param string $message message to deliver
* @param boolean $willEcho (default false) Boolean to determine if
you will view the echoed response
* @param int $port (default 25)
* @param int $timeout (default 30)
* @return mixed $response Response can either be 1 (true) or either 0
for false or the error message if you will be returning the echoes
* @see smtp_connect
* @see smtp_command
* @see smtp_close
*/
function &checkbounceback($domain, $from, $to, $message, $willEcho =
false, $port = 25, $timeout = 30) {
@ob_start();
$handle = smtp_connect($domain, $port, $timeout, 1, 1, 1);
echo smtp_command($handle, "EHLO $domain\r\n", 1, 1);
echo smtp_command($handle, "MAIL FROM:<$from>\r\n", 1, 1);
echo smtp_command($handle, "RCPT TO:<$to>\r\n", 1, 1);
echo smtp_command($handle, "DATA\r\n", 1, 1);
echo smtp_command($handle, "$message\r\n.\r\n", 1, 1);
echo smtp_command($handle, "QUIT\r\n", 1, 1);
smtp_close($handle);
$response = @ob_get_contents();
@ob_end_clean();
if ($willEcho) return $response;
}
}
print_r(checkbounceback('smtp.erols.com', 'me@here.com',
'me@erols.com', 'willEcho')); // NOTE THAT "me@erols.com" IS NOT MY
REAL EMAIL ADDRESS BUT I USE MY REAL EMAIL ADDRESS THERE INSTEAD IN THE
SCRIPT
[/PHP]
To check with my email on the SMTP domain "smtp.erols.com" I get the
following results:
[quote]
CONNECTING TO smtp.erols.com
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed:
Temporary failure in name resolution in
/var/www/html/app/globals/functions.inc.php on line 1634
Warning: fsockopen(): unable to connect to smtp.erols.com:25 in
/var/www/html/app/globals/functions.inc.php on line 1634
CONNECTION FAILED
EHLO smtp.erols.com
MAIL FROM:
RCPT TO:
DATA
Er du der?
..
QUIT
[/quote]
So basically, what on earth did I do wrong?
Phil
Navigation:
[Reply to this message]
|