HI Appreciate any answers regarding this. I'm unable to get my php form to work even after double checking the variable over and again.
This is the form tag beginning -
<form name="sentMessage" action="contact.php" method="post" id="contactForm">
My PhP below -
<?php
$myemail = 'nikhilnayak.in@gmail.com';
$name = check_input($_POST['name'], "Enter your name");
$email = check_input($_POST['email'], "Enter your E-mail ID");
$phone = check_input($_POST['phone'], "Enter your Contact #");
$refemail = check_input($_POST['refemail']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$subject = 'New Website Lead' ;
$headers = "From: $name";
$message = "
Name: $name
E-mail: $email
Contact #: $phone
References:
$refemail
" ;
mail($myemail, $subject, $message, $headers);
header('Location: thankyou.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
[HTML BODY HERE}
<?php
exit();
}
?>
Please guys, any help is useful. This has been uploaded and its not working even when live...
This is the HTML form -
<form name="sentMessage" action="contact.php" method="post" id="contactForm">
<div class="row control-group">
<div>
<label style="margin-right:85px; font-size:16px;">Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div>
<label style="margin-right:20px; font-size:16px;">Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div>
<label style="margin-right:15px; font-size:16px;">Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number (+974)" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<p>If you would like to refer someone else or if you have multiple e-mail IDs, enter them below</p>
<div class="row control-group">
<div>
<label style="margin-right:40px; font-size:16px;">References</label>
<input type="tel" class="form-control" placeholder="Email 1; Email 2; Email 3" id="refemail" required data-validation-required-message="Please the E-mail IDs.">
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row" style="display:inline-block; text-align:center;">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
UPDATE ----
HI GUYS, thanks for your answers... removed the re-validation in the PHP and it seems to re-direct to the thank you page... but the email i get is blank (without the $name, $phone, etc...)
new PHP code -
$name = check_input($_REQUEST['name']);
$email = check_input($_REQUEST['email']);
$phone = check_input($_REQUEST['phone']);
$refemail = check_input($_REQUEST['refemail']);
and i have removed the below code.
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
UPDATE
Answered by linil