Log in

View Full Version : Invalid eMail Address(check) with PHP Script Form



andy8828
12-18-2010, 04:55 AM
Hello,

I have a greeting card web page which it used to work fine before in 4 or 5 years ago(It now hosts at oneandone.com).

But now it has the "invalid check email address" error when trying to click on the submit "Preview eCard" button. The php script code may be not compatible with the new PHP server. Can someone help me to fix this email check error? Thanks.

Here is part of the php code and the URL of the web page http://www.uswebcity.com/greetings/index.php.


<?php
function validate_email ($address) {
return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
$address));
}

function checkemail($address){
if (!validate_email($address)) {
?>
<html><head><title>Invalid Email Address</title></head>
<body bgcolor=white>
<h3>Invalid Email Address:</h3>
<p>Sorry, the email address <font color=red><?php print $address ?></font> is invalid.</p>
<form>
<INPUT TYPE="button" VALUE="Go Back" onClick="history.back()">
</form>
</body></html>
<?php
exit;
}
}

checkemail($recipientemail);
checkemail($senderemail);

$message = trim($message);
$showmessage = stripslashes($message);
$message = htmlentities($showmessage);

djr33
12-18-2010, 05:49 AM
The old ereg functions have been replaced by the preg functions. They're 'better', but that means some old scripts stop working.

Try this instead:

return (preg_match('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
$address));

I'm not an expert with regular expressions, but it looks like the two functions are generally compatible. Test it to be sure. Hope it helps.

andy8828
12-18-2010, 09:58 PM
Thank you for your reply.

If I replaced the "ereg" with "preg_match", I will get this error message.


Warning: preg_match() [function.preg-match]: Unknown modifier '_' in /homepages/33/d138037059/htdocs/greetings/preview.php on line 7
Invalid Email Address:

Sorry, the email address is invalid.

djr33
12-19-2010, 12:08 AM
Hm, looks like it's trying to treat the underscore as an operator rather than a character to match. I'm not sure how to fix it, but you should look into how the preg functions allow underscores.