473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do I prevent bogus email addresses with legit domains? I thought this worked

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', 'm*@here.com',
'm*@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:

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
So basically, what on earth did I do wrong?

Phil

Nov 10 '06 #1
2 2016
comp.lang.php wrote:
I came up with functions that I thought would do the trick:
<code snipped>
So basically, what on earth did I do wrong?

Phil
Phil,

You are not connecting to the SMTP server - as the message said,
getaddrinfo failed, and it's considered a temporary failure.

A lot of things could cause this. A bad domain name, a hiccup in the
DNS you're using, a bad "hosts" file entry, a firewall are some examples.

Can you telnet to smtp.erols.com port 25 from your server?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 11 '06 #2

Jerry Stuckle wrote:
comp.lang.php wrote:
I came up with functions that I thought would do the trick:
<code snipped>
So basically, what on earth did I do wrong?

Phil
Phil,

You are not connecting to the SMTP server - as the message said,
getaddrinfo failed, and it's considered a temporary failure.

A lot of things could cause this. A bad domain name, a hiccup in the
DNS you're using, a bad "hosts" file entry, a firewall are some examples.

Can you telnet to smtp.erols.com port 25 from your server?
I can telnet to it but it just hangs my terminal window and I have to
close it, I cannot escape out.

I found out that when I test on the live server it works much moreso
than on the development server which has no email server. How can I
detect if I have an email server so as not to try to connect to the
remote email server if my server is incapable of doing so?

Secondly, I still can't tell if the email address is bogus or valid
because it just sends an email instead of telling me that the email
exists on the remote server.

Phil
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Spammay Blockay | last post by:
Does anybody know of a solid Java-based email list management product? - Tim --
5
by: Peter Murray | last post by:
Hi! I hope someone can assist me, I have been using Python for a year or two, but I am not a programmer and only use it occasionally for small issues or just for fun. So I perhaps do not have the...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
8
by: JayB | last post by:
We sent out an email today to a list of subscribers from our database using ASP and CDO. For some reason, many people received it twice, including myself. I checked the database and there were do...
117
by: Steevo | last post by:
Any suggestions as to the best programs for cloaking email addresses? Many thanks -- Steevo
12
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses...
11
by: tshad | last post by:
I have a W2003 server running my website and I am trying to set up my pages to send email using System.Web.Mail. I have pages running on this machine using CDONTS that work fine. I am using...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
23
by: codefire | last post by:
Hi, I am trying to get a regexp to validate email addresses but can't get it quite right. The problem is I can't quite find the regexp to deal with ignoring the case james..kirk@fred.com, which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.