Post by fido-x » Thu Oct 08, 2009 2:33 pm

I get a lot of "customers" creating accounts with bodgy email addresses, so I've been looking at some way of validating email addresses a bit better than the current method, which only checks that the email address is of the corrrect "form" (ie. username@domain.com).

I'm still working on this, but at least the following code will check that the domain actually exists.

In "catalog/controller/account/create.php", in the validate() function (lines 283 to 285), by replacing the following:-

Code: Select all

if (!preg_match($pattern, $this->request->post['email'])) {
       $this->error['email'] = $this->language->get('error_email');
}
with:

Code: Select all

if (!preg_match($pattern, $this->request->post['email'])) {
	$this->error['email'] = $this->language->get('error_email');
} else {
	list($uname, $domain) = split('@', $this->request->post['email']);
	if (!getmxrr($domain, $mxhost)) {
		$this->error['email'] = $this->language->get('error_email');
	} elseif (!fsockopen($domain, 25)) {
		$this->error['email'] = $this->language->get('error_email');
	}
}
You can, at least, verify that the domain actually exists. I've only been able to get this working at the create stage so far. Doesn't seem to work for account edit. I'm still looking into this.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by nzjolly » Fri Oct 09, 2009 3:24 am

is there also a problem with sub domains? have a few problems with <name>.<name>@subdomain.<domain>.<ext> address's.

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by fido-x » Fri Oct 09, 2009 9:49 am

Yes, it would appear that there are problems with subdomains. The above code works by checking if there is an MX record for the domain. If there isn't, it then checks to see if port 25 is open. If neither of these are true, it will return an error.

The big problem is that, while a person's email address is "username@domain.com", quite often "domain.com" does not have an MX record or an open port 25. Reason being that the mail server is called "mail.domain.com". Subsequently, it will always return an error. Testing on my local machine didn't find this problem, but on my live server, it was a different story.

Using the following, as an alternative, might work:-

Code: Select all

if (!preg_match($pattern, $this->request->post['email'])) {
	$this->error['email'] = $this->language->get('error_email');
} else {
	list($uname, $domain) = split('@', $this->request->post['email']);
	if (!checkdnsrr($domain)) {
		$this->error['email'] = $this->language->get('error_email');
	}
}
as this only checks the DNS entry and doesn't check for any MX record or an open port 25.

I've only tried this on my local machine so far and it works there, but I don't know whether it will work on a live server as yet. I'll be testing that later on today.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by rocketero » Fri Mar 11, 2011 12:30 pm

How is this going? has been more than a year and a half from last post.
keep us posted.

New member

Posts

Joined
Tue Feb 01, 2011 9:22 pm

Post by fido-x » Fri Mar 11, 2011 2:20 pm

Yeah, this is an old post. Like I said above, I was able to get it working on the localhost, but wasn't able to get it working on my live server for some reason. Never actually nailed it down as to why, so I just gave up on it.

For me, it was more of an annoyance with getting "undeliverable emails" filling up my inbox than anything else, as I wasn't actually "selling" anything at the time. Since putting a price tag on some of my modules, the number of "bodgy" email addresses has dropped.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Active Member

Posts

Joined
Tue Jan 11, 2011 5:41 am
Location - Ukraine

Post by t_mask17 » Mon Mar 14, 2011 2:39 pm

Did your code has an updated at the online testing.. I mean did it works online now?

Hope you could reply on this post.. thanks

Newbie

Posts

Joined
Mon Mar 14, 2011 2:33 pm

Post by afwollis » Wed Mar 16, 2011 7:17 am

I have a few places, where it is used.
but cant provide a link at this moment.

I will add it to "create account" page in my test opencart store and then will post a link here.
you will be able to test it by yourself :)

but please note:
my code does not check if domain (of the email address) exists or not.

Русское коммьюнити разработчиков OpenCart - myopencart.ru

some useful mods:
[Released] Orders and Comments AT-A-GLANCE, [Released] Prof. Invoice and Packingslip, [Released] Recently viewed

My commercial modules: [W]ebme Compare Products, [W]ebme Bought With This


Active Member

Posts

Joined
Tue Jan 11, 2011 5:41 am
Location - Ukraine
Who is online

Users browsing this forum: No registered users and 3 guests