Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:17:16+00:00 2026-06-12T01:17:16+00:00

I am trying to make a form that is secure from spam and sends

  • 0

I am trying to make a form that is secure from spam and sends a simple email to the person who registers.

Im quite new to PHP and the problem im faced with is when the form is submitted with a false email address in the email field, it brings up the error message stating that the email is invalid, but still lets the registration go through adding it to the database.

here is the code

function spamcheck($field) {
    // filter_var() sanitizes the e-mail
    // address using FILTER_SANITIZE_EMAIL
    $field = filter_var($field, FILTER_SANITIZE_EMAIL);

    // filter_var() validates the e-mail
    // address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}

if(isset($_REQUEST['email'])) {
    // if "email" is filled out, proceed
    // check if the email address is invalid
    $mailcheck = spamcheck($_REQUEST['email']);
    if ($mailcheck==FALSE) {
        die("<font color='red'>Your email address is invalid, please try again.</font><br/><br/><form><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'></form>");
    }
    else {//send email
        $to = "$email";
        $from = "name@mywebsite.com";
        $message = "Just a message";
        $subject = "Subject";

        mail($to, $message, $subject, "From: $from", "-f$from");
    }
}

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:17:17+00:00Added an answer on June 12, 2026 at 1:17 am

    Maybe the problem here is, that your check-function first sanitizes the email address, and afterwards validates the sanitized email. That means, the check-function checks the sanitized email, but outside of the function you are still working with the invalid email.

    So either do the sanitizing outside of the check function, or in my opinion even better, only validate the input without sanitization (better to make the user aware that he typed it incorrect, than trying to repair it).

    function checkEmail($input)
    {
      return filter_var($input, FILTER_VALIDATE_EMAIL);
    }
    

    Edit:

    Actually there must be another problem, because when the code die(...Your email address is invalid...) is executed, the processing of the page stops. We would need to see the part of the code, which writes to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a simple form that contains textboxes that draw from a
I trying to make a Control that inherits from System.Windows.Form.Label that can resize to
I’m trying to make a html5 form that contains one email input, one check
I'm trying to to make a form that will submit a new record and
I'm trying to make a simple Windows form app that does things. I'd like
Basically I am trying to make a simple form that allows the user to
I am trying to make a simple Windows Form application that will show different
I'm trying to make an AJAX form that will update a twitter status when
Trying to make a custom :confirm message for a rails form that returns data
I am trying to make a form field for a datetime property that allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.