www.webdeveloper.com
Results 1 to 6 of 6

Thread: Stopping a script

  1. #1
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,096

    Stopping a script

    I built a site that tests email servers.

    http://emailpermutator.com

    The script will permutate a name and company to generate email addresses and then test them.
    Sometimes, someone will enter an address that is not a mail server, yet my script continues to run through all of the permutations while delivering the message that the mailserver cannot be contacted.

    For example, I entered John Doe and set his domain at gsk.be

    John@gsk.be None of the mailservers listed for gsk.be could be contacted

    This message will repeat as it tries all permutations.
    How could I stop the script after receiving this message just once?

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    you could blacklist or delete the email address. blacklisting would probably be the better option to pick.
    crude example
    PHP Code:
    $list = array(
        
    // ...
    );
    $fail = array(
        
    // ...
    );

    while (list(, 
    $email) = each($list)) {
        if (
    in_array($email$fail))
            continue;
        if (
    test_email($email)) {
            
    // all's well...
        
    } else {
            
    $fail[] = $email;
        }
    }
    // save the blacklist...
    // to file or database or w/e 

  3. #3
    Join Date
    May 2014
    Posts
    900
    Over on another (now defunct) forums another user and I came up with this check for valid e-mail addresses:

    Code:
    function isValidEmail($address) {
    	if (filter_var($address,FILTER_VALIDATE_EMAIL)==FALSE) {
    		return false;
    	}
    	/* explode out local and domain */
    	list($local,$domain)=explode('@',$address);
    	
    	$localLength=strlen($local);
    	$domainLength=strlen($domain);
    	
    	return (
    		/* check for proper lengths */
    		($localLength>0 && $localLength<65) &&
    		($domainLength>3 && $domainLength<256) &&
    		(
    			checkdnsrr($domain,'MX') ||
    			checkdnsrr($domain,'A')
    		)
    	);
    }
    FILTER_VALIDATE_EMAIL checks everything except for proper lengths, so we explode at the @ to get the Local Name and Domain name lengths. If those lengths are valid, we check that the domain has either a MX or A record with checkdnsrr.

    Not all servers have a proper MX set up, hence the need to check if a A record exists too.

    A simple DNS check of the domain as above should filter out the majority of invalid domains.
    Java is to JavaScript as Ham is to Hamburger.

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,096
    Thanks DeathShadow - but validation is not what I was trying to do. That is already working on my page.

    ShrineDesigns example worked, but it returns false negatives.
    I built it and began testing, but it tells me some servers are not working, when in fact they are working mail servers.

    Here is the page I made to test this script:
    http://emailpermutator.com/tester/server-test.php


    Any other ideas?

  5. #5
    Join Date
    May 2014
    Posts
    900
    Then I'm not sure what you are even trying to do -- it almost sounds like you are blindly spamming servers with random addresses, which should get you banned from mailing after 3 responses if the server configuration makes even the least bit of sense. I know mine is.

    I'd have thought that checkdnsrr would be sufficient to see if it even is a mail server, the only scenario in which "The mail server could not be contacted" should arise in significant numbers.
    Java is to JavaScript as Ham is to Hamburger.

  6. #6
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    Quote Originally Posted by donatello View Post
    ShrineDesigns example worked, but it returns false negatives.
    test_email() is not a function. I simply placed it there as an example to illustrate testing the email address.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles