Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Problem emailing online


Irin

Recommended Posts

Posted

Hello,

 

I have a lot of people complaining that they have a problem to email me by using either Contact Us form or Ask a Product Question form. The forms keep rejecting their valid email addresses by saying that they were "invalid". Why is this happening and how can I fix the issue?

 

Any help will be appreciated.

Thanks.

Posted
I have a lot of people complaining that they have a problem to email me by using either Contact Us form or Ask a Product Question form. The forms keep rejecting their valid email addresses by saying that they were "invalid". Why is this happening and how can I fix the issue?

 

what is their email address? if it has one of the newer top level domains, like .asia, you might need to add it to your tld.txt file. there are two of them located in catalog/includes/ and catalog/admin/includes.

Posted
what is their email address? if it has one of the newer top level domains, like .asia, you might need to add it to your tld.txt file. there are two of them located in catalog/includes/ and catalog/admin/includes.

The emails are mostly coming from .com domain and the people emailng from all over the world. I think the problem is with the emal verification, not every .com domain is accepted. I think that I added a Contact Us Spam Issue Fixes module some time ago if it matters at all. But that was just for the contact us form and the problem is also with Ask a Product Question form, so I'm not really sure if that's the problem. How is the email verification working and where do I need to look for the problem?

 

Thanks.

Posted
The emails are mostly coming from .com domain and the people emailng from all over the world. I think the problem is with the emal verification, not every .com domain is accepted. I think that I added a Contact Us Spam Issue Fixes module some time ago if it matters at all. But that was just for the contact us form and the problem is also with Ask a Product Question form, so I'm not really sure if that's the problem. How is the email verification working and where do I need to look for the problem?

 

email validation is done in the tep_validate_email() function in catalog/includes/functions/validations.php. if your 'contact us spam issue fixes' mod changes this, it is used everywhere email validation is needed and therefore could be used in your 'ask a product question' form. you may have made a mistake when you installed that mod.

 

alternatively, at the bottom of the tep_validate_email() function is a call to checkdnsrr() - this looks for a valid 'mx' (mail exchange) dns record. these are used by mail servers to find a domain's email server. maybe the target email address doesn't have the mx record set? if this is the case, you can turn this off by going to admin -> configuration -> email options -> verify email address through dns = 'false'. this defaults to false, but you may have turned it on. without knowing the domain of the email, that's the best i can do. if this doesn't work, please reply with the domain - i can then see what checkdnsrr() returns for that domain and see if that's the problem.

 

i hope this helps.

Posted
email validation is done in the tep_validate_email() function in catalog/includes/functions/validations.php. if your 'contact us spam issue fixes' mod changes this, it is used everywhere email validation is needed and therefore could be used in your 'ask a product question' form. you may have made a mistake when you installed that mod.

 

alternatively, at the bottom of the tep_validate_email() function is a call to checkdnsrr() - this looks for a valid 'mx' (mail exchange) dns record. these are used by mail servers to find a domain's email server. maybe the target email address doesn't have the mx record set? if this is the case, you can turn this off by going to admin -> configuration -> email options -> verify email address through dns = 'false'. this defaults to false, but you may have turned it on. without knowing the domain of the email, that's the best i can do. if this doesn't work, please reply with the domain - i can then see what checkdnsrr() returns for that domain and see if that's the problem.

 

i hope this helps.

The "Contact Us Spam Issue Fixes" requires an addition of only one function to the /includes/functions/validations.php that prevents spam emails from own domain.

function tep_email_isfromdomain($email) {
list($username,$domain)=split('@',$email);
$domain = strtolower($domain);
 if ($domain == '' . HTTP_MAIL_DOMAIN . ''){
 return true;
 }else{
 return false;
 }
}

I also have some additional validate_email code (I'm not sure where it came from) in my /includes/functions/validations.php:

/* START validate_email */
if($valid_address){
 getmxrr( $domain, $mx_records, $mx_weight );

  // copy mx records and weight into array $mxs
  $mxs=array();

  for($i=0;$i<count($mx_records);$i++){
	$mxs[$mx_weight[$i]]=$mx_records[$i];
  }

  // sort array mxs to get servers with highest prio
  ksort ($mxs, SORT_NUMERIC );
  reset ($mxs);

  $mail_ok = false;
  while (!$mail_ok && list ($mx_weight, $mx_host) = each ($mxs) ) {
	//try connection on port 25
	$fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
	if($fp){
	  $ms_resp=get_data($fp);

	  // say HELLO to mailserver
	  $ms_resp.=send_command($fp, "HELLO " . substr(EMAIL_FROM, strpos(EMAIL_FROM, "@")));

	  // initialize sending mail
	  $ms_resp.=send_command($fp, "MAIL FROM: <" . EMAIL_FROM . ">");

	  // try receipent address, will return 250 when ok..
	  $rcpt_text=send_command($fp, "RCPT TO: <".$email.">");
	  $ms_resp.=$rcpt_text;

	  if(substr( $rcpt_text, 0, 3) == "250")
		$mail_ok=true;

	  // quit mail server connection
	  $ms_resp.=send_command($fp, "QUIT");

	fclose($fp);
	}
  }
  if(!$mail_ok) {
	 $valid_address = false;
  }
}
/* END validate_email */

return $valid_address;
 }

 /* START validate_email */
 function send_command($fp, $out){

fwrite($fp, $out . "\r\n");
return get_data($fp);
 }

 function get_data($fp){
$s="";
stream_set_timeout($fp, 2);

for($i=0;$i<2;$i++)
  $s.=fgets($fp, 1024);

return $s;
 }
 /* END validate_email */

I checked the Admin -> Configuration -> Email Options and Verify Email Addresses Through DNS is set to 'false'.

Posted
The "Contact Us Spam Issue Fixes" requires an addition of only one function to the /includes/functions/validations.php that prevents spam emails from own domain.

 

ok....so where and how is this new tep_email_isfromdomain() function used? is it called from somewhere within validations.php? and i can't really understand the context of the new validate_email code. i need to see where exactly that code is within the file.

 

how about you post the entire validations.php code so i can see its use in context? i get the feeling that the problem is lurking in there somewhere....

Posted
ok....so where and how is this new tep_email_isfromdomain() function used? is it called from somewhere within validations.php? and i can't really understand the context of the new validate_email code. i need to see where exactly that code is within the file.

 

how about you post the entire validations.php code so i can see its use in context? i get the feeling that the problem is lurking in there somewhere....

Dave, thanks a lot for your help. I found what was causing the problem. It's the "validate_email" plugin by Bisente. It verifies the e-mail by tep_validate_email, establishes a connection to port 25 of the customer's mail server, and issues a couple of SMTP commands (EHLO, MAIL FROM and RCTP TO) to check if the address really exists. Here is my entire validations.php:

<?php
/*
 $Id: validations.php,v 1.11 2003/02/11 01:31:02 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 ////////////////////////////////////////////////////////////////////////////////////////////////
 //
 // Function	: tep_validate_email
 //
 // Arguments   : email   email address to be checked
 //
 // Return	  : true  - valid email address
 //			   false - invalid email address
 //
 // Description : function for validating email address that conforms to RFC 822 specs
 //
 //			   This function is converted from a JavaScript written by
 //			   Sandeep V. Tamhankar ([email protected]). The original JavaScript
 //			   is available at http://javascript.internet.com
 //
 // Sample Valid Addresses:
 //
 //	[email protected]
 //	[email protected]
 //	"first last"@host.com
 //	"first@last"@host.com
 //	[email protected]
 //	first.last@[123.123.123.123]
 //
 // Invalid Addresses:
 //
 //	first [email protected]
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////
 function tep_email_isfromdomain($email) {
list($username,$domain)=split('@',$email);
$domain = strtolower($domain);
 if ($domain == '' . HTTP_MAIL_DOMAIN . ''){
 return true;
 }else{
 return false;
 }
}

 function tep_validate_email($email) {
$valid_address = true;

$mail_pat = '^(.+)@(.+)$';
$valid_chars = "[^] \(\)<>@,;:\.\\\"\[]";
$atom = "$valid_chars+";
$quoted_user='(\"[^\"]*\")';
$word = "($atom|$quoted_user)";
$user_pat = "^$word(\.$word)*$";
$ip_domain_pat='^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$';
$domain_pat = "^$atom(\.$atom)*$";

if (eregi($mail_pat, $email, $components)) {
  $user = $components[1];
  $domain = $components[2];
  // validate user
  if (eregi($user_pat, $user)) {
	// validate domain
	if (eregi($ip_domain_pat, $domain, $ip_components)) {
	  // this is an IP address
		for ($i=1;$i<=4;$i++) {
		  if ($ip_components[$i] > 255) {
			$valid_address = false;
			break;
		  }
	  }
	}
	else {
	  // Domain is a name, not an IP
	  if (eregi($domain_pat, $domain)) {
		/* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD
		   and that there's a hostname preceding the domain or country. */
		$domain_components = explode(".", $domain);
		// Make sure there's a host name preceding the domain.
		if (sizeof($domain_components) < 2) {
		  $valid_address = false;
		} else {
		  $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]);
		  // Allow all 2-letter TLDs (ccTLDs)
		  if (eregi('^[a-z][a-z]$', $top_level_domain) != 1) {
			$tld_pattern = '';
			// Get authorized TLDs from text file
			$tlds = file(DIR_WS_INCLUDES . 'tld.txt');
			while (list(,$line) = each($tlds)) {
			  // Get rid of comments
			  $words = explode('#', $line);
			  $tld = trim($words[0]);
			  // TLDs should be 3 letters or more
			  if (eregi('^[a-z]{3,}$', $tld) == 1) {
				$tld_pattern .= '^' . $tld . '$|';
			  }
			}
			// Remove last '|'
			$tld_pattern = substr($tld_pattern, 0, -1);
			if (eregi("$tld_pattern", $top_level_domain) == 0) {
				$valid_address = false;
			}
		  }
		}
	  }
	  else {
		  $valid_address = false;
		}
	  }
  }
  else {
	$valid_address = false;
  }
}
else {
  $valid_address = false;
}
if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') {
  if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
	$valid_address = false;
  }
}

/* START validate_email */
if($valid_address){
   getmxrr( $domain, $mx_records, $mx_weight );

  // copy mx records and weight into array $mxs
  $mxs=array();

  for($i=0;$i<count($mx_records);$i++){
	$mxs[$mx_weight[$i]]=$mx_records[$i];
  }

  // sort array mxs to get servers with highest prio
  ksort ($mxs, SORT_NUMERIC );
  reset ($mxs);

  $mail_ok = false;
  while (!$mail_ok && list ($mx_weight, $mx_host) = each ($mxs) ) {
	//try connection on port 25
	$fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
	if($fp){
	  $ms_resp=get_data($fp);

	  // say HELLO to mailserver
	  $ms_resp.=send_command($fp, "HELLO " . substr(EMAIL_FROM, strpos(EMAIL_FROM, "@")));

	  // initialize sending mail
	  $ms_resp.=send_command($fp, "MAIL FROM: <" . EMAIL_FROM . ">");

	  // try receipent address, will return 250 when ok..
	  $rcpt_text=send_command($fp, "RCPT TO: <".$email.">");
	  $ms_resp.=$rcpt_text;

	  if(substr( $rcpt_text, 0, 3) == "250")
		$mail_ok=true;

	  // quit mail server connection
	  $ms_resp.=send_command($fp, "QUIT");

	fclose($fp);
	}
  }
  if(!$mail_ok) {
 	  $valid_address = false;
  }
}
/* END validate_email */

return $valid_address;
 }

 /* START validate_email */
 function send_command($fp, $out){

fwrite($fp, $out . "\r\n");
return get_data($fp);
 }

 function get_data($fp){
$s="";
stream_set_timeout($fp, 2);

for($i=0;$i<2;$i++)
  $s.=fgets($fp, 1024);

return $s;
 }
 /* END validate_email */

?>

When I removed all the code within /* START validate_email */ and /* END validate_email */, the forms work perfect, no more invalid emails. I already sent the email to the plugin author notifying him of the problem. Hope he'll reply with the fix.

 

Thanks again for your efforts.

Posted
Dave, thanks a lot for your help. I found what was causing the problem. It's the "validate_email" plugin by Bisente. It verifies the e-mail by tep_validate_email, establishes a connection to port 25 of the customer's mail server, and issues a couple of SMTP commands (EHLO, MAIL FROM and RCTP TO) to check if the address really exists. Here is my entire validations.php:

 

hmm...interesting. the code looks okay, but it's entirely dependent on whether or not the email recipient's mail server allows you to connect to it. a lot of mail servers are not allowing this any more in order to reduce spam. so if these domains have tighter controls on emails, their addresses can't be verified in this way.

Posted
hmm...interesting. the code looks okay, but it's entirely dependent on whether or not the email recipient's mail server allows you to connect to it. a lot of mail servers are not allowing this any more in order to reduce spam. so if these domains have tighter controls on emails, their addresses can't be verified in this way.

It could be, so I just removed all that validate_email code because I have no idea how it works, therefore can't fix it by myself. Now, the form doesn't care if there is a valid email or misspelled, just submits the comments. Well... at least I won't have angry customers that can't email me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...