PHP validation fail - php

I created Err code so that name and radio has to be checked otherwise it can't move on to the confirmation page and send error message next to the field. Please help if I'm missing any code!
<?php
$nameErr = $charityErr = "";
$name = $charity = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is missing";
}
else {
$name = $_POST["name"];
}
if (!isset($_POST["charity"])) {
$charityErr = "You must select 1 option";
}
else {
$charity = $_POST["charity"];
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link type="text/css" href="testStyle.css" rel="stylesheet"/>
<title>Survey</title>
</head>
<body>
<div><!--start form-->
<form method="post" action="submit.php">
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "1") echo "checked"; ?> value="1">1
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "2") echo "checked"; ?> value="2">2
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "3") echo "checked"; ?> value="3">3
<span class="error"><?php echo $charityErr;?></span>
<input type="text" name="name" placeholder="ENTER YOUR COMPANY NAME">
<span class="error"><?php echo $nameErr;?></span>
<input type="submit" name="submit" value="Submit"/>
</form>
</div><!--end form-->
</body>
</html>
My submit.php says:
/* Subject and Email Variables */
$emailSubject = 'Survey!';
$webMaster = 'myname#email.com';
/* Gathering Data Variables */
$name = $_POST ['name'];
$charity = $_POST ['charity'];
//create a new variable called $body line break, say email and variable, don't leave any space next to EOD - new variable $body 3 arrows less than greater than, beyond EOD no spaces
$body = <<<EOD
<br><hr><br>
Company Name: $name <br>
Charity: $charity <br>
EOD;
//be able to tell who it's from
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results rendered as HTML */
$theResults = <<<EOD
<html>
blah blah
</html>
This redirects fine to submit.php page except my validation doesn't work and sends blank data.
Form code is above as:
<form method="post" action="submit.php">
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "1") echo "checked"; ?>
value="1">1
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "2") echo "checked"; ?>
value="2">2
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "3") echo "checked"; ?>
value="3">3
<span class="error"><?php echo $charityErr;?></span>
<input type="text" name="name" placeholder="ENTER YOUR COMPANY NAME">
<span class="error"><?php echo $nameErr;?></span>
<input type="submit" name="submit" value="Submit"/>
</form>

You have a syntax error here:
<?php if (isset($charity) && charity == "3") echo "checked"; ?>
You miss $ in charity var:
<?php if (isset($charity) && $charity == "3") echo "checked"; ?>
About your second question, I think that your form is a little messy.
You can use the same page to the form, validation, error management and proccesing, using this structure:
capture vars
validating
proccesing
show errors if any or success msg
render form if error or not sent
Try some like this:
<?php
//Capture POST/GET vars
$charity = $_REQUEST['charity'];
$name = $_REQUEST['name'];
$step = $_REQUEST['step'];
//You can add some sanitizing to the vars here
//Form sent if step == 1
if ($step == 1){
/*
* Validate form
*/
//Initialize error's array
$error = array();
//No charity value error
if (!$charity){
$error[] = 'You must select 1 option';
}
//Missing name error
if (!$name){
$error[] = 'Name is missing';
}
//Add any other validation here
/*
* Process form if not error
*/
if (!$error){
//Send eMail
$subject = "Your subject here";
$toemail = "<yourname#example.com>";
$bounce = "<bounce#example.com>";
$message = "
Company Name: $name<br>
Charity: $charity <br>";
$subject = '=?UTF-8?B?'.base64_encode(utf8_encode($subject)).'?=';
$headers = "From: <webform#example.com>" . "\r\n" .
"Reply-To: <info#example.com>" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($toemail, $subject, $message, $headers, "-f $bounce" );
//Add any other proccesing here, like database writting
}
/*
* Show errors || succsess msg on the top of the form
*/
if ($error){
unset($step); //if error, show the form
echo '<div style="color:yellow;background-color:red;">ERROR:<br>';
foreach ($error as $e){
echo '- '.$e.'<br>';
}
echo '</div><br>';
}else{
echo '<div>Form succesfully sent</div><br>';
}
}
/*
* Form rendering
*/
if (!$step){
?>
<form method="post" action="">
<input type="radio" name="charity" value="1" <?php echo ($charity == "1") ? ' checked':''; ?>>1
<input type="radio" name="charity" value="2" <?php echo ($charity == "3") ? ' checked':''; ?>>2
<input type="radio" name="charity" value="3" <?php echo ($charity == "3") ? ' checked':''; ?>>3
<input type="text" name="name" placeholder="ENTER YOUR COMPANY NAME">
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
}

Related

Self Submit PHP Form Validation

I've made a PHP form to submit to self with error validation, but the form is not submitting. The idea is, when the user clicks on the submit button and hasn't filled in all required fields or email address they entered is flawed, then errors occur by adding an error class that's sorted by CSS. The CSS is fine, but the form is not submitting. I'd appreciate the help.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Email</title>
</head>
<body>
<?php
$error = '';
$to = "name#example.com";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"]) || empty($_POST["email"]) || empty($_POST["message"])) {
$error = 'class="error" ';
} else {
$name = stripslashes(trim($_POST["name"]));
$email = stripslashes(trim($_POST["email"]));
$message = stripslashes(trim($_POST["message"]));
$pattern = '/[\r\n]|Content-Type:|Bcc:|Cc:/i';
if (preg_match($pattern, $name) || preg_match($pattern, $email)) {
$error = 'class="error" ';
}
$emailIsValid = filter_var($email, FILTER_VALIDATE_EMAIL);
if ($name && $email && $emailIsValid && $message) {
$subject = "From $name";
$body = "Name: $name <br /> Email: $email <br /> Message: $message";
$headers = "Reply-To: $email";
$success = mail($to, $subject, $body, $headers);
if ($success) {
header("Location: /email/sent/");
} else {
header("Location: /error/");
}
}
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?>">
<input <?php echo $error; ?>type="text" name="name" placeholder="Full Name" spellcheck="false">
<input <?php echo $error; ?>type="text" email="email" placeholder="Email Address" spellcheck="false">
<textarea <?php echo $error; ?>type="text" message="message" placeholder="Message" rows="6" spellcheck="false"></textarea>
<button type="submit" name="submitted">submit</button>
</form>
</body>
</html>
NOTE : You have typo mistakes in your form tag.you used double quote inside double quote.
Insted of using this
<form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?>">
and
if ($_SERVER["REQUEST_METHOD"] == "POST") {
Use
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
and
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submitbutton'])) {
//SO IT WILL PERFORM ONLY WHEN SUBMIT BUTTON WAS PRESSED
For More You can Learn it here
Or Also Live Demo is available

How to send multiple emails to only selected user's emails in php?

I am trying to send emails to only the users which i am selecting using checkbox from same index.php page. i am trying something here but i don't know that how to transfer and hold checked emails to "Bcc" field. here, is my code please have a look !
Php code for email (index.php) :
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$to = "";
$headers = "From:$name<$email>";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $selectedemailsall\r\n";
$message = "Name: $name\n\n Email: $email \n\n Subject : $subject \n\n Message : $comments";
if(mail($to,$subject,$message,$headers))
{
echo "Email Send";
}
else
{
echo "Error : Please Try Again !";
}
}
?>
Code for form (index.php) :
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mail Document</title>
</head>
<body>
<form action="" method="post" >
<p>Name :<br>
<input type="text" name="name" id=""></p>
<p>Email :<br>
<input type="text" name="email" id=""></p>
<p>Subject :<br>
<input type="text" name="subject" id=""></p>
<p>Comments :<br>
<textarea name="comments" id="" cols="30" rows="10"></textarea></p>
<p><input type="submit" value="Send Email" name="SubmitEmail"></p>
</form>
<form action="#" method="post">
<?php
error_reporting(E_ERROR | E_PARSE);
$connection = mysqli_connect("localhost","root", "");
$db = mysqli_select_db("testdb", $connection);
$query = mysqli_query("select * from users", $connection);
while ($row = mysqli_fetch_array($query))
{
echo "
<input type='checkbox' name='check_list[]' value='{$row['email']}'>
<label>{$row['username']}</label><br/>
";
}
?>
<?php
if(isset($_POST['submituserchk']))
{
//to run PHP script on submit
if(!empty($_POST['check_list']))
{
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selectedemails)
{
$selectedemailsall = $selectedemails.",";
//echo $selectedemailsall;
}
}
}
?>
</div> <!-- End of RightUsersDivWithCheckBox -->
<input type="submit" name="submituserchk" style="margin-left: 87%; margin-top: 20px;" value="Done"/>
</form>
</body>
</html>
Any solution please how to do this ? right now when i click "Done" and submit emails nothing happens and i don't want to click "Done" button after selecting emails. I just select emails and they goes to "Bcc" field in a variable.
Don't use Bcc header for many users. Yo can make is:
Your form:
...
<input type="checkbox" name="email[]" value="foo#host.tld"> - foo#host.tld
<input type="checkbox" name="email[]" value="bar#host.tld"> - bar#host.tld
<input type="checkbox" name="email[]" value="baz#host.tld"> - baz#host.tld
...
Your backend code:
...
if (array_key_exists('email', $_POST) && is_array($_POST['email'])) {
foreach ($_POST['email'] as $to) {
mail($to, $subject, $message, $headers);
}
}
...
All emails sent separatelly for all recipients. This is flexible case for your application -- you can check for each send status.
Finally i got an answer to my own question. below is my code,
Display username, emails with checkbox from database :
$getemail = mysqli_query("SELECT * FROM users",$connection);
if(!$getemail) die('MsSQL Error: ' . mysqli_error());
echo '<div class="AllUserDiv" style="overflow-y:scroll;height:400px;"><table class="table table-bordered">';
echo "<thead>
<tr>
<th><input type='checkbox' onchange='checkedbox(this)' name='chk' /> </th>
<th>Username</th>
<th>Email</th>
</tr>
</thead>";
if(mysqli_num_rows($getemail) == 0)
{
echo "<tbody><tr><td colspan='3'> No Data Available</td></tr></tbody>";
}
while($row = mysqli_fetch_assoc($getemail))
{
echo "<tbody><tr><td><input value='".$row['email']."' type='checkbox' name='check[]' checked /> </td>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['email']."</td></tr></tbody>";
}
Email Form :
<form method="post" action="">
<p style="margin-top:30px;">Email Subject: <input type="text" name="subject" value="" class="form-control" /></p>
<p>Email Content: <textarea name="message" cols="40" rows="6" style="width:100%;"></textarea></p>
<center><input type="submit" name="submit" value="Send Email Now" class="btn btn-primary btn-block" />
</form>
JavaScript for making checkbox selection :
<script type="text/javascript" language="javascript">
function checkedbox(element)
{
var checkboxes = document.getElementById('input');
if(element.checked)
{
for (var i = 0; i < checkboxes.length; i++ )
{
if(checkboxes[i].type == 'checkbox')
{
checkboxes[i].checked = true;
}
}
}
else
{
for (var i = 0; i < checkboxes.length; i++)
{
console.log(i)
if(checkboxes[i].type == 'checkbox')
{
checkboxes[i].checked = false;
}
}
}
}
</script>

simple php captcha contact form

i am trying to create simple contact form with captcha in php. However it turns out implementing captcha is out of my league.
I found a simple answer on stackoverflow opn similar problem which pushed me 1 step closer to the end, but again i got stuck.
So i need a contact form that only check if text is entered and if correct captcha is answered, email is not mandatory.
</br>
<?php
$a=rand(2,9);
$b=rand(2,9);
$c=$a+$b;
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha == $c )) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
} else {
echo 'Neteisingai užpildyta forma.';
}
}
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php echo $a."+".$b."="?><input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input type="submit" value="Siusti">
<br>
</form>
Now the problem is that I always get the message that details are incorrect. I tried to echo recaptcha just to see if $c is correct and it works. But for some reason not able to compare $recaptcha with $c or some other issue I am not sure.
The value of $c will be a completely different value when the user submits the contact form vs when your validation checks it. The value will change on every request because the script is re-interpreted.
You will have to save the value of $c on the initial page load, so that you can compare it afterwards in the next request. You can do that by storing it in $_SESSION.
You can write this
<?php
$min_number = 2;
$max_number = 9;
$random_number1 = mt_rand($min_number, $max_number);
$random_number2 = mt_rand($min_number, $max_number);
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$firstNumber = $_POST["firstNumber"];
$secondNumber = $_POST["secondNumber"];
$checkTotal = $firstNumber + $secondNumber;
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha != $checkTotal )) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
} else {
echo 'Neteisingai užpildyta forma.';
}
}
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php
echo $random_number1 . ' + ' . $random_number2 . ' = ';
?>
<input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input name="firstNumber" type="hidden" value="<?php echo $random_number1; ?>" />
<input name="secondNumber" type="hidden" value="<?php echo $random_number2; ?>" />
<input type="submit" value="Siusti">
<br>
</form>
This might solve your problem
you should to use session to solve your problem, i did little changes in your code, it should to work perfectly.
<?php
#session_start();
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha == $_SESSION["captcha"])) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
}else{
echo 'Neteisingai užpildyta forma.';
}
}else{
$a=rand(2,9);
$b=rand(2,9);
$c=$a+$b;
//setting captcha code in session
$_SESSION["captcha"] = $c;
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php echo $a."+".$b."="?><input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input type="submit" value="Siusti">
<br>
</form>
<?php
}
?>

Contact form modification

I made a contact form a year ago, and have been re-using the code ever since.
It is just 3 text boxes but I need to add a Select option, but I have no idea how to add php to it.
This is one of the sections of the php, it's all the same other than naming so no need to post it all.
<?php
error_reporting(E_ALL ^ E_NOTICE);
if(isset($_POST['submitted'])) {
if(trim($_POST['contactFirstName']) === '') {
$nameError = 'Forgot your name!';
$hasError = true;
} else {
$name = trim($_POST['contactFirstName']);
}
if(!isset($hasError)) {
$emailTo = 'dezfouli.lila#live.com';
$subject = 'Submitted message from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
This is one of the text boxes
<form id="contact-us" action="book.php" method="post">
<div class="formblock">
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactFirstName'])) echo $_POST['contactFirstName'];?>" class="txt requiredField" placeholder=" First Name:" />
<?php if($nameError != '') { ?>
<br /><span class="error"><?php echo $nameError;?></span>
<?php } ?>
</div>
I need to now make it work with this:
<div class="formblock">
<select name="month">
<option value="date">Month
<option value="1">January
<option value="2">February
<option value="3">March
</select>
<?php if($emailError != '') { ?>
<br /><span class="error"><?php echo $emailError;?></span>
<?php } ?>
</div>
You can access which value has been submitted by getting the value of $_POST['month']
For Example:
if (isset($_POST['month']) && $_POST['month'] != 'date') {
// add your code here
}
You also need to close your option tags as so:
<div class="formblock">
<select name="month">
<option value="date">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
</select>
<?php if($emailError != '') { ?>
<br /><span class="error"><?php echo $emailError;?></span>
<?php } ?>
</div>

My PHP form submits but does not validate the email address

I am an eager novice with PHP so please forgive my errors as I am learning as I go. Basically, I am building a simple contact form for my website and have successfully been able to have the form send the user's first and last name, subject, email address and message. I am using a second file, "form_process.php" to process the form data from "index.php".
The problem is that the email address does not seem to be validating and will send any words typed. I would greatly appreciate it if some more seasoned eyes could take a look and help me sort this out. Thank you in advance.
Michael.
HTML:
<div id="form">
<form action="form_process.php" method="post" enctype="multipart/form-data">
<p>
<input type="text" maxlength="100" size="50" name="fName" value="<?php echo $stored_fName;?>" placeholder="First Name" />
</p>
<p>
<input type="text" maxlength="100" size="50" name="lName" value="<?php echo $stored_lName;?>" placeholder="Last Name" />
</p>
<p>
<input type="text" maxlength="80" size="50" name="email" value="<?php echo $stored_email;?>" placeholder="Email Address" />
</p>
<p>
<input type="text" maxlength="100" size="50" name="subject" value="<?php echo $stored_subject;?>" placeholder="Subject" />
</p>
<p>
<textarea name="message" rows="6" cols="38" placeholder="Message"></textarea>
</p>
<br />
<input type="submit" value="Submit" name="submit" />
<input type="reset" value="Clear" name="clear">
</form>
</div>
<!-- form ends -->
PHP: "form_process.php"
<?php
session_start();
// Report all PHP errors
error_reporting(E_ALL);
//use $_POST to to store data from submitted form into these variables
$fName = check_input($_POST['fName']);
$lName = check_input($_POST['lName']);
$sender = check_input($_POST['email']);
$subject = check_input($_POST['subject']);
$message = check_input($_POST['message']);
//check_input function to strip unnessessary characters and sanitize user data
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$name = $fName ." ". $lName;//concatenating first and last names to new name variable
$sanitizedEmail = filter_var($sender, FILTER_SANITIZE_EMAIL);
//generates error messages on index.php if form fields left blank
if ($fName == ''){
header("Location:index.php?message=1");
exit();
}
if ($lName == ''){
header("Location:index.php?message=2");
exit();
}
if ($sender == ''){
header("Location:index.php?message=3");
exit();
}
if ($subject == ''){
header("Location:index.php?message=4");
exit();
}
if ($message == ''){
header("Location:index.php?message=5");
exit();
}
//headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= $name . "\r\n";
$headers .= "From:" . " " . $sanitizedEmail . "\r\n";
//mail function
$to = "me#myemail.com";
$subject = $subject;
$message = $message;
//send message
$send_message = mail($to,$subject,$message,$headers);
if($send_message){
header("Location:index.php?message=6");
}else {
header("Location:index.php?message=9");
exit();
}
?>
"index.php" error messages:
<?php
//all fields empty until user inputs data for session to store
$stored_fName = '';//init as NULL
$stored_lName = '';//init as NULL
$stored_email = '';//init as NULL
$stored_subject = '';//init as NULL
$stored_message = '';//init as NULL
//session data used to repopulate form fields if any info is missing or incorrect
if (isset($_SESSION['fName'])){
$stored_fName = $_SESSION['fName'];
}
if (isset($_SESSION['lName'])){
$stored_lName = $_SESSION['lName'];
}
if (isset($_SESSION['email'])){
$stored_email = $_SESSION['email'];
}
if (isset($_SESSION['subject'])){
$stored_subject = $_SESSION['subject'];
}
if (isset($_SESSION['message'])){
$stored_message = $_SESSION['message'];
}
//error messages displayed to user if text fields have been left blank
$_GET['message'];
if ($_GET['message'] == 1) {//first name
echo "<strong>Please type your first name.</strong>";
}
if ($_GET['message'] == 2) {//last name
echo "<strong>Please type your last name.</strong>";
}
if ($_GET['message'] == 3){//email address
echo "<strong>Please type an email address.</strong>";
}
if ($_GET['message'] == 4){//subject
echo "<strong>Please type a subject.</strong>";
}
if ($_GET['message'] == 5){//message text
echo "<strong>Please type your message.</strong>";
}
if ($_GET['message'] == 6){//message success from form_process.php
echo "<strong>Your message was sent successfully. Thank you.</strong>";
}
if ($_GET['message'] == 9){
echo "<strong>I'm sorry but your message was not sent. Please try again, thank you.</strong>";
}
?>
You should be using it like this:
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
// is email
$sender = $email;
}else{
// isn't email
$sender = '';
}
Read more about PHP Validate Filters

Categories