droidman Posted November 15, 2010 Share Posted November 15, 2010 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 15, 2010 Share Posted November 15, 2010 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. Quote Link to comment Share on other sites More sharing options...
droidman Posted November 15, 2010 Author Share Posted November 15, 2010 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 15, 2010 Share Posted November 15, 2010 Are they in a database, or in a text file now? You mention both . . . Quote Link to comment Share on other sites More sharing options...
droidman Posted November 15, 2010 Author Share Posted November 15, 2010 Are they in a database, or in a text file now? You mention both . . . better to go by textfile. that way i can export more databases and run more tests in the future. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2010 Share Posted November 16, 2010 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); } } ?> Quote Link to comment Share on other sites More sharing options...
droidman Posted November 16, 2010 Author Share Posted November 16, 2010 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!! 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! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2010 Share Posted November 16, 2010 You might need to use \r\n . . . \n works for me, but I'm on a Mac. Quote Link to comment Share on other sites More sharing options...
droidman Posted November 16, 2010 Author Share Posted November 16, 2010 You might need to use \r\n . . . \n works for me, but I'm on a Mac. IT WORKS! THANK YOU!!! Quote Link to comment Share on other sites More sharing options...
droidman Posted November 16, 2010 Author Share Posted November 16, 2010 You might need to use \r\n . . . \n works for me, but I'm on a Mac. by the way, is it possible to make the "proper" validation using phpmail under php or just by software and using proxy ? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2010 Share Posted November 16, 2010 Not sure what you're asking, really . . . Quote Link to comment Share on other sites More sharing options...
droidman Posted November 17, 2010 Author Share Posted November 17, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.