Grow your CSS skills. Land your dream job.

Getting a "Enter Valid Email Address" error

  • # August 4, 2009 at 11:35 pm

    Hi all,
    When I hit submit on my contact form I am getting an error telling me that the email address that was entered is not valid, even though I am testing it out with valid email addresses.
    I will go ahead and post up the pattern I am using to validate:

    Code:
    // If the email is set, validate and store it
    if(!empty($_POST['cf_e']) && $_POST['cf_e']!=’Email (required)’)
    {
    // Define a regex pattern to validate the email address
    $pattern = “/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i”;
    if (preg_match($pattern, $_POST['cf_e']))
    {
    $email = $_POST['cf_e'];
    }

    else
    {
    // If the email doesn’t match the pattern, error
    $err .= “Please enter a valid email address!
    “;
    }
    }

    I even looked up another pattern to use and it still didn’t work. Does anyone have any suggestions?

    # August 7, 2009 at 8:12 pm

    Well I got the error issue taken care of, but something is still wrong and I just can’t figure it out.
    When I send the message, it looks like everything works fine and goes through with no errors, but when I check my email there is no message there. Anyone have any ideas what might be causing this?

    # August 7, 2009 at 8:59 pm

    Are you working with PHP on your local machine, or on an external server and FTPing all your files up there? If you are using your computer with something like MAMP or XAMMP set up, most likely the server won’t be set up properly to send mail. I’d suggest uploading your files to your web host and testing it live there.

    # August 7, 2009 at 11:52 pm

    Thanks for the reply. I wish I could say that I wasn’t using my external server, but yes, I am FTPing them to my hosts server.

    # August 8, 2009 at 1:04 am

    Have you been able to send emails using that host in the past? I know some hosts disable it for spam reasons.

    (In case you don’t know, you can check if it is disabled by looking at a file with this contents: <?php phpinfo(); ?>)

    # August 8, 2009 at 3:07 am

    Well it has worked in the past with a different contact form script that I used to use. I got too much spam with that one and wanted to try a new one. So I’m pretty sure it isn’t disabled, but thanks for your input! I’ll take any suggestions! I’m ready to pull my hair out. It doesn’t help that I’m ignorant to php! I uploaded the php to a syntax error checker and it passed it fine though.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".