Results 1 to 4 of 4

Thread: Invalid eMail Address(check) with PHP Script Form

  1. #1
    Join Date
    Jul 2008
    Location
    USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Invalid eMail Address(check) with PHP Script Form

    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 Code:
    <?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);

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    PHP Code:
    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2008
    Location
    USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •