Jump to content

Recommended Posts

This may have been answered in some way before, but I am trouble locating code that works properly. I am trying to validate an email address beyond checking the DNS of the e-mail’s domain to make sure it has a proper MX Record. Which I have working but with the following code, I am getting an error OR sometimes what I guess is the server timing out:

function checkEmail($email) {
// checks proper syntax
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
// gets domain name
list($username,$domain)=split('@',$email);
// checks for if MX records in the DNS
if(!checkdnsrr($domain, 'MX')) {
return false;
}
// attempts a socket connection to mail server
if(!fsockopen($domain,25,$errno,$errstr,30)) {
return false;
}
return true;
}
return false;
}

$email = trim('test@test.com');
if(!checkEmail($email)) { 
echo 'Bad!';
}
else {
echo 'Good';
}

 

Warning: fsockopen() [function.fsockopen]: unable to connect to test.com:25 (Connection timed out) in /home/linux/[xxx]/testing.php on line 75

Bad!

 

I get the same warning for all domains, even real emails addresses...I have found several pieces of code and gone through several of the examples on the php.net site but I am not able to get the above to behave itself. I know my host doesn't allow pfockopen as it is disabled but it seems to allow fsockopen. The above also doesn't work all the time, sometimes it will produce an internal server error!

 

Thanks in advance for any help.

 

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/
Share on other sites

I'm using

ereg("^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$", $mail);

and it's a really good one. It takes care of almost all possible addresses - but there is NO regex which fits for all addresses!!

 

 

@ sKunKbad: i've never heard of the function "filter()" in PHP and also didn't find a reference?! Do you have more information?

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554692
Share on other sites

Thanks for your replies.

 

I didn't realize that my regex syntax checker maybe causing problems, but I will look at that.

 

I had a look at the filter() function provided by php, but again other than finding how to use it at w3schools I can't actually find how it is filtering email and I am somewhat reluctant to use it.

 

I would if possible like to get the fsockopen to work, since I believe it is meant to check more thoroughly if the email address is valid.

 

My other alternative is to instead of directly send the data from their form to its correct destination is to send the user a activation/confirmation email, and store their sanitized form details in a database, if they reply then that too will increase the possibility that a bot or other malicious entity is not involved.

 

But just as a matter of knowledge, I am still confused as to why the fsockopen is not behaving. The port numbers I am using seem to be somewhat restrictive, so perhaps that is it, but perhaps someone has a suggestion for a script  or function that will resolve (pun intended) this issue.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554712
Share on other sites

Hi Kaliok

 

If you check out my website (www.phishspit.com) it sounds like you have been trying to achieve something similar to what I have done.

 

Just enter an email header in to the form and click "Submit". On the results page you should find a result which states whether an email address is valid or not.

 

Tell me if this is the sort of thing you were after? If it is I can tell you how it was done.

 

Best Regards

 

 

 

Tom

 

PS An opinion on what you think about the site would be appreciated too  ;D

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554714
Share on other sites

But just as a matter of knowledge, I am still confused as to why the fsockopen is not behaving. The port numbers I am using seem to be somewhat restrictive, so perhaps that is it, but perhaps someone has a suggestion for a script  or function that will resolve (pun intended) this issue.

 

An confirmation link is the only and best way to be sure that the email address at least exists. I don't know what you want to do with fsocks. You will never be able to find out if an address exists with it. The only thing you can check is: "Is there an MX-Entry" for that domain" (which means there is at least a mail server for @domain.com addresses)

 

I check with regex combined with this MX-check.

 

kind Regards

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554719
Share on other sites

Hi Benedikt

 

As we are on the subject of email validation etc. You will see from the trail I have compiled something similar to this which checks if an email address exists or not, but also gives out other various bits of info.

 

Would appreciate your opinion on it. How reliable do you think the site is?

 

Cheers

 

 

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554721
Share on other sites

Hi Tom - The form you have on your site does indeed look like what I am trying to achieve. The site looks good and does what it says on the tin :). Any advice on how you did this would be great. Thanks.

 

The fsocks thing seems to be being used in several places that I found using google and "email validation" but perhaps they are wrong.

 

 

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554723
Share on other sites

Hi Kaliok

 

As promised, I found the code from this site:

 

http://www.howtocreate.co.uk/php/dnld.php?file=4&action=1

 

Obviously mine has been adapted, but the outcome is the same.  :)

 

This code does use fsockopen in it's method. There is a full explanation on there showing how it should be used etc.

 

Hope this is OK.

 

Any probs let me know.

 

Best Regards

 

 

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554725
Share on other sites

Hi Tom

 

Thanks so much for pointing me at the url. Initial tests seem to be working. I am still not why email validation isn't build into a php function, unless that is what the filter function mentioned above is doing.  I can't think of any reason why anyone would want to collect and/or use emails that are bogus and even if they did the function could be have a boolean parameter to turn it of and on. Anyway thanks for your advice.

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554729
Share on other sites

Hi Kaliok

 

As promised, I found the code from this site:

 

http://www.howtocreate.co.uk/php/dnld.php?file=4&action=1

 

Obviously mine has been adapted, but the outcome is the same.  :)

 

This code does use fsockopen in it's method. There is a full explanation on there showing how it should be used etc.

 

Hope this is OK.

 

Any probs let me know.

 

Best Regards

 

 

The problem is that (most) mailing protocols do not tell you if the mail address is existing unless address and password fits. I gave your posted script a try but like I thought it didn't work the way it was wanted. (Please tell me if I did something wrong) The regex worked fine, but invalid addresses were not found (most times)

Here you have my test-log. I deleted real addresses for security reason. Every second address does NOT exists; the first, third, fith and seventh are existing. i tested google (gmail), gmx, a personal mail server and hotmail.

 

Received email address: ***********@hotmail.com

Email address was recognised as a valid email pattern

Obtained the following MX records for hotmail.com: mx1.hotmail.com (5), mx2.hotmail.com (5), mx3.hotmail.com (5), mx4.hotmail.com (5)

Checking MX server: mx1.hotmail.com

Created socket (Resource id #1) to mx1.hotmail.com

mx1.hotmail.com sent SMTP connection header - no futher MX servers will be checked: 220 bay0-mc6-f23.bay0.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.msn.com/Anti-spam/. Violations will result in use of equipment located in California and other states. Sun, 1 Jun 2008 04:36:34 -0700

mx1.hotmail.com rejected HELO: 554 Transaction failed

Email address was rejected by mx1.hotmail.com

Email address does not seem to be valid

 

 

Received email address: beasdfaaavasdos@hotmail.com

Email address was recognised as a valid email pattern

Obtained the following MX records for hotmail.com: mx1.hotmail.com (5), mx2.hotmail.com (5), mx3.hotmail.com (5), mx4.hotmail.com (5)

Checking MX server: mx1.hotmail.com

Created socket (Resource id #2) to mx1.hotmail.com

mx1.hotmail.com sent SMTP connection header - no futher MX servers will be checked: 220 bay0-mc4-f12.bay0.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.msn.com/Anti-spam/. Violations will result in use of equipment located in California and other states. Sun, 1 Jun 2008 04:36:35 -0700

mx1.hotmail.com rejected HELO: 554 Transaction failed

Email address was rejected by mx1.hotmail.com

Email address does not seem to be valid

 

 

Received email address: ***********@gmx.at

Email address was recognised as a valid email pattern

Obtained the following MX records for gmx.at: mx0.gmx.de (10), mx0.gmx.net (10)

Checking MX server: mx0.gmx.de

Created socket (Resource id #3) to mx0.gmx.de

mx0.gmx.de sent SMTP connection header - no futher MX servers will be checked: 220 mx0.gmx.net GMX Mailservices ESMTP {mx088}

mx0.gmx.de sent HELO response: 250 mx0.gmx.net GMX Mailservices {mx088}

mx0.gmx.de sent MAIL FROM response: 250 2.1.0 ok {mx088}

mx0.gmx.de rejected recipient: 550-5.7.1 {mx088} Sorry, your helo has been denied.

Email address was rejected by mx0.gmx.de

Email address does not seem to be valid

 

 

Received email address: aasdfasdadfos@gmx.at

Email address was recognised as a valid email pattern

Obtained the following MX records for gmx.at: mx0.gmx.de (10), mx0.gmx.net (10)

Checking MX server: mx0.gmx.de

Created socket (Resource id #4) to mx0.gmx.de

mx0.gmx.de sent SMTP connection header - no futher MX servers will be checked: 220 mx0.gmx.net GMX Mailservices ESMTP {mx044}

mx0.gmx.de sent HELO response: 250 mx0.gmx.net GMX Mailservices {mx044}

mx0.gmx.de rejected MAIL FROM: 550 5.1.7 <aasdfasdadfos@gmx.at>... User is unknown {mx044}

Email address was rejected by mx0.gmx.de

Email address does not seem to be valid

 

 

Received email address: ***********@gmail.com

Email address was recognised as a valid email pattern

Obtained the following MX records for gmail.com: gmail-smtp-in.l.google.com (5), alt1.gmail-smtp-in.l.google.com (10), alt2.gmail-smtp-in.l.google.com (10), gsmtp147.google.com (50), gsmtp183.google.com (50)

Checking MX server: gmail-smtp-in.l.google.com

Created socket (Resource id #5) to gmail-smtp-in.l.google.com

gmail-smtp-in.l.google.com sent SMTP connection header - no futher MX servers will be checked: 220 mx.google.com ESMTP f77si8512157pyh.15

gmail-smtp-in.l.google.com sent HELO response: 250 mx.google.com at your service

gmail-smtp-in.l.google.com sent MAIL FROM response: 250 2.1.0 OK

gmail-smtp-in.l.google.com sent RCPT TO response: 250 2.1.5 OK

Email address was accepted by gmail-smtp-in.l.google.com

Email address seems to be validReceived email address: asdfasdfasdfasdf@gmail.com

Email address was recognised as a valid email pattern

Obtained the following MX records for gmail.com: gmail-smtp-in.l.google.com (5), alt1.gmail-smtp-in.l.google.com (10), alt2.gmail-smtp-in.l.google.com (10), gsmtp147.google.com (50), gsmtp183.google.com (50)

Checking MX server: gmail-smtp-in.l.google.com

Created socket (Resource id #6) to gmail-smtp-in.l.google.com

gmail-smtp-in.l.google.com sent SMTP connection header - no futher MX servers will be checked: 220 mx.google.com ESMTP a2si3537590pyi.28

gmail-smtp-in.l.google.com sent HELO response: 250 mx.google.com at your service

gmail-smtp-in.l.google.com sent MAIL FROM response: 250 2.1.0 OK

gmail-smtp-in.l.google.com rejected recipient: 550-5.1.1 This Gmail user does not exist. Please try double-checking

Email address was rejected by gmail-smtp-in.l.google.com

Email address does not seem to be valid

 

 

Received email address: ***********@vamos-inc.at

Email address was recognised as a valid email pattern

Obtained the following MX records for vamos-inc.at: mail405.ixwebhosting.com (10)

Checking MX server: mail405.ixwebhosting.com

Created socket (Resource id #7) to mail405.ixwebhosting.com

mail405.ixwebhosting.com sent SMTP connection header - no futher MX servers will be checked: 220 mail405.opentransfer.com ESMTP

mail405.ixwebhosting.com sent HELO response: 250 mail405.opentransfer.com

mail405.ixwebhosting.com sent MAIL FROM response: 250 ok

mail405.ixwebhosting.com sent RCPT TO response: 250 ok

Email address was accepted by mail405.ixwebhosting.com

Email address seems to be validReceived email address: basdfasdfkt@vamos-inc.at

Email address was recognised as a valid email pattern

Obtained the following MX records for vamos-inc.at: mail405.ixwebhosting.com (10)

Checking MX server: mail405.ixwebhosting.com

Created socket (Resource id #8) to mail405.ixwebhosting.com

mail405.ixwebhosting.com sent SMTP connection header - no futher MX servers will be checked: 220 mail405.opentransfer.com ESMTP

mail405.ixwebhosting.com sent HELO response: 250 mail405.opentransfer.com

mail405.ixwebhosting.com sent MAIL FROM response: 250 ok

mail405.ixwebhosting.com sent RCPT TO response: 250 ok

Email address was accepted by mail405.ixwebhosting.com

Email address seems to be valid

 

 

 

Fazit: For hotmail and gmx it does NOT work. Gmail is the only one where the script works!! and for my personal server it always say its valid *lol*

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554754
Share on other sites

Hi Guys

 

:(. That's a tad annoying. I just tested it with a few more real emails that were real and it failed them. Although the real hotmail addresses I tried all passed! I think that there needs to be some kind of gauge or ranking that the email gets. I have seen this on an ASP function. I found this on http://centralops.net/co/EmailDossier.vbs.asp - it seems to do a more comprehensive check and passed or almost passed more emails than the one on howtocreate. Not good at translating asp to php though...

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554786
Share on other sites

Hello All

 

I think I am getting somewhere. Well, kind of!! :)

 

Could you do me a favour and try putting in various email headers supposedly from hotmail email addresses? And also try the GMX ones too?

 

I am still working on Yahoo by the way!! LOL

 

Could you tell me if you have a better success rate, and whether the results the phishspit.com website is showing are correct (or what you would expect to see anyway)?

 

Any problems, shout! :)

 

Cheers

 

 

 

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554874
Share on other sites

hotmail words pretty good...! gmx was no problem too.

 

it doesn't work at all with other mailservers...

 

yahoo I didn't try (don't know addresses)

 

 

... don't you just have to get it working for the three kinds of mailservers (smtp, pop3, ..) or do other organizations like for example gmx have their own system (of course not...)?

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554889
Share on other sites

it doesn't work at all with other mailservers...

 

Not sure what you mean by that. Is it a problem you are encountering on PhishSpit.com? Or do you just mean generally?

 

The problem with the MX results occurs, from what I can see, when you have a hotmail.co.uk email address, but the mx servers are on hotmail.com, for example. What seems to happen at the end of the running script is that it does another check for hotmail.co.uk mx records, then I think it must confuse itself or something, thus it seems to give wrong info as a result. If you look at your GMX example, it mentions gmx.at, gmx.de AND gmx.net in the responses.

 

All I did was capture the information BEFORE it gets to that stage.

 

Does that make sense?

 

Best Regards

 

 

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554900
Share on other sites

it doesn't work at all with other mailservers...

 

Not sure what you mean by that. Is it a problem you are encountering on PhishSpit.com? Or do you just mean generally?

 

 

I mean it doesn't work with my addresses for example ((AT)vamos-inc.at) I tried my address at phishspit.com and it meant that this address doesn't exist. (My webspace is professional hosted...) I know that my provider does POP before SMTP what means that your smtp request only get handled right if you connected with POP before.

 

It is great if your idea works with hotmail,gmx, yahoo and gmail... but what about the rest?

 

 

I agree with you, that could make sense :)

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554918
Share on other sites

Ah right OK.

 

Could you do me a favour then? Could you fill out the contact form on the website and leave me your contact details. I will then reply and ask you to send me through some email header examples and other bits and pieces which will allow me to replicate this error and get this resolved?

 

If you could do that for me that would be great.

 

Cheers for your help on this one.

 

Best Regards

 

 

 

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/108173-email-validation/#findComment-554940
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.