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 8463549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:29:07+00:00 2026-06-10T14:29:07+00:00

I created a contact us form which should be simple and most importantly secure,

  • 0

I created a contact us form which should be simple and most importantly secure, so user can’t enter code to be executed on the server side:

<?php

$userips = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

$ips = $userips;

// Clean up the input values
foreach($_POST as $key => $value) {
  if(ini_get('magic_quotes_gpc'))
    $_POST[$key] = stripslashes($_POST[$key]);

  $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}


// Assign the input values to variables for easy reference
$name = $_POST["name"];
$email = $_POST["email"];
$reason = $_POST["reason"];
$message = $_POST["message"];

mail($to, $subject, $message, $headers);

// Send the email
$to = "test@testsite.com";
$subject = "From: $name . " Reason: " . $reason";
$message = "$message" . "\n\n\n==-   Sent from the website with IP Address: " . $ips . "   -==";;
$headers = "From: $email";



$send_contact=mail($to,$subject,$message,$header);


header("Location: http://www.testsite.com");


// Check, if message sent to your email
// display message "We've recived your information"
// if($send_contact){
// echo "We've recived your contact information";
// }
// else {
// echo "ERROR";
// }
?>

Will the above code do the job? Or am I missing codes to ensure the security is set in place?

EDIT
I have the following Jquery script which checks for email validity:

'email' : function() {

    $('body').append('<div id="emailInfo" class="info"></div>');

    var emailInfo = $('#emailInfo');
    var ele = $('#email');
    var pos = ele.offset();

    emailInfo.css({
        top: pos.top-3,
        left: pos.left+ele.width()+15
    });

    var patt = /^.+@.+[.].{2,}$/i;

    if(!patt.test(ele.val())) {
        jVal.errors = true;
            emailInfo.html('<img src=theImages/xMark.png title="Please enter a valid email address" alt="Please enter a valid email address" />').show();
            ele.removeClass('normal').addClass('wrong');                    
    } else {
            emailInfo.html('<img src=theImages/checkMark.gif />').show();
            ele.removeClass('wrong').addClass('normal');
    }
},

With the above code, can i leave the ELSE statement blank in the php code?

  • 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-10T14:29:08+00:00Added an answer on June 10, 2026 at 2:29 pm

    What you do need to look out for are email injections. You can put up a defense against them by using:

    filter_var($email, FILTER_SANITIZE_EMAIL)
    

    Your script had a number of mistakes, including parse errors:

    <?php
    
    $userips = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    
    $ips = $userips;
    
    // Clean up the input values
    foreach($_POST as $key => $value) {
      if(ini_get('magic_quotes_gpc'))
        $_POST[$key] = stripslashes($_POST[$key]);
    
      $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
    }
    
    
    // Assign the input values to variables for easy reference
    $name = $_POST["name"];
    $email = $_POST["email"];
    $reason = $_POST["reason"];
    $message = $_POST["message"];
    
    
    if(filter_var($email, FILTER_SANITIZE_EMAIL)){
        // Send the email
        $to = "test@testsite.com";
        $subject = "From: $name Reason: $reason";
        $message = "$message" . "\n\n\n==-   Sent from the website with IP Address: " . $ips . "   -==";;
        $headers = "From: $email";
    
        $send_contact=mail($to,$subject,$message,$headers);
        header("Location: http://www.testsite.com");
    }
    else{
        echo 'Bold!';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one form, which contain information of user like name, contact no,
I have created a contact form which will email me once sent. Now I
I have the following script which creates an email from a contact form: http://codeviewer.org/view/code:1b54
I have created a basic contact form, and when the user submits information, it
I created a contact form with a text area input only field, which allows
I created a form for a Wordpress theme, using Easy Contact Form' plugin which
I'm using Contact Form 7 plugin in a WordPress template. I created the form
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I have a contact form, the values of which I'm passing to a php
I have the following code, which is supposed to create a form on the

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.