Jump to content

Load multiple e-mails and validate them


droidman

Recommended Posts

hi, im new here i hope to learn and help in the way i can since i'm a newbie with php but here it goes.

 

I have some old databases i need to test, i want to mail these old users from a website i had but i need to know if the database contains invalid e-mails and remove them so i dont mess up my server's good ip reputation.

So i found the checkdnsrr function:

function checkEmail($email) {
// checks proper syntax
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) {

	// gets domain name
	list($username,$domain)=split('@',$email);
	// checks for if MX records in the DNS
	if(!checkdnsrr($domain, 'MX')) {
		return false;
	}
	return true;
}
return false;
}

 

so everyone knows this function, i just wanted to run it to multiple e-mail addresses like from a text file. when i say multiple, i mean arround 500.000 or 50k at the time. i just want to output the bad e-mails to a text file.

hope someone can help me on this one.

thanks in advance

 

Link to comment
Share on other sites

All that does validate the address format and tell you if the domain has a valid DNS MX entry associated with it. It won't tell you if the actual address is valid or not.

 

Hi Pikachu2000, i know about that, that is what i need right now. i just want to know if their domain still works.

Link to comment
Share on other sites

This will work, but I suspect it will take an enormous amount of time to run. Probably be best if you break up the text file into smaller chunks and run them that way. You'll need to create the good_addresses.txt and bad_addresses.txt files in the same directory as the script (or edit the path), and it assumes the addresses are each on their own line in the all_addresses.txt file. I know there has to be a better, more efficient way; I just can't think of it at the moment.

 

<?php
function checkEmail($email) {
   // checks proper syntax
   if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) {

      // gets domain name
      list($username,$domain)=split('@',$email);
      // checks for if MX records in the DNS
      if(!checkdnsrr($domain, 'MX')) {
         return false;
      }
      return true;
   }
   return false;
}

$email = file('all_addresses.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach( $email as $v ) {
   if( checkEmail($v) ) {
      file_put_contents('good_addresses.txt', "$v\n", FILE_APPEND);
   } else {
      file_put_contents('bad_addresses.txt', "$v\n", FILE_APPEND);
   }
}
?>

Link to comment
Share on other sites

This will work, but I suspect it will take an enormous amount of time to run. Probably be best if you break up the text file into smaller chunks and run them that way. You'll need to create the good_addresses.txt and bad_addresses.txt files in the same directory as the script (or edit the path), and it assumes the addresses are each on their own line in the all_addresses.txt file. I know there has to be a better, more efficient way; I just can't think of it at the moment.

 

<?php
function checkEmail($email) {
   // checks proper syntax
   if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) {

      // gets domain name
      list($username,$domain)=split('@',$email);
      // checks for if MX records in the DNS
      if(!checkdnsrr($domain, 'MX')) {
         return false;
      }
      return true;
   }
   return false;
}

$email = file('all_addresses.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach( $email as $v ) {
   if( checkEmail($v) ) {
      file_put_contents('good_addresses.txt', "$v\n", FILE_APPEND);
   } else {
      file_put_contents('bad_addresses.txt', "$v\n", FILE_APPEND);
   }
}
?>

 

Oh thank you!!  :D

Ok it takes a while to process but it WORKS! Very simple and light i cannot thank you enough!

just one thing.

file_put_contents('good_addresses.txt', "$v\n", FILE_APPEND);

The line break is not working, i get all the mails pasted together so i used a ";" instead so that my software can understand the separation but if you know an line break like one email per line please let me know.

and once again, THAN YOU!

Link to comment
Share on other sites

Not sure what you're asking, really . . .

 

hi mate sory for the delay and keep you waiting ( i guess :) )

 

There are some programs out there that validate e-mail addresses by doing this:

[01] 11/17 12:08:04 MX <MYMAIL@gmail.com> -> [alt1.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com]
[01] 11/17 12:08:04 > CONNECT TO: [alt1.gmail-smtp-in.l.google.com]
[01] 11/17 12:08:04 220 mx.google.com ESMTP w12si5813152eeh.80
[01] 11/17 12:08:04 > HELO Jorge-PC
[01] 11/17 12:08:04 250 mx.google.com at your service
[01] 11/17 12:08:04 > MAIL FROM:<fitness@gmail.com>
[01] 11/17 12:08:04 250 2.1.0 OK w12si5813152eeh.80
[01] 11/17 12:08:04 > RCPT TO:<MYMAIL@gmail.com>
[01] 11/17 12:08:05 250 2.1.5 OK w12si5813152eeh.80

 

This is done either by smtp or other method that i dont know, and it validates mails like 90% successfull rate. it only needs a dedicated server ip to work. so people use proxy's to do it.

is it possible to do it under php ?

 

ps: the line [01] 11/17 12:08:05 250 2.1.5 OK w12si5813152eeh.80 says that the mail is OK so it is valid, no mail goes out, the server quits the operation here and verifies other mails.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.