Recaptcha validation fail: please check the captcha - php

The relevant form:
<script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="contactform">
<div id="details">
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Full name *:</label><br>
<input type="text" name="name">
</p>
<p>
<label for='address'>Address *:</label><br>
<input type="text" name="address">
</p>
<p>
<label for='unit'>Unit:</label><br>
<input type="text" name="unit">
</p>
<p>
<label for='postal'>Postal code *:</label><br>
<input type="text" name="postal">
</p>
<p>
<label for='email'>Email:</label> <br>
<input type="text" name="email">
</p>
<p>
<label for='phone'>Telephone *:</label><br>
<input type="text" name="phone">
</p>
<p>
<label for='date'>Preferred pickup date* :</label> <br>
<input type="date" name="date">
</p>
<p>
<label for='time'>Preferred timeslot* :</label><br>
<span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span><br>
<input type="text" name="time1"> to <input type="text" name="time2">
</p>
</div>
<div id="products">
<p><label for='itemsharp'>Items for sharpening:</label><br>
<textarea name="itemsharp"></textarea>
</p>
<p>
<label for='itemrepair'>Items for repair:</label><br>
<textarea name="itemrepair"></textarea>
</p>
<p>
<label for='comment'>Comment: </label><br>
<textarea name="comment"></textarea>
</p>
<div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div>
<input class="button" type="submit" value="Submit"><br>
</form>
</div>
</div>
The php:
<?php
$errors = '';
$myemail = '[aperfectlyvalidemailadress]';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['address']) ||
empty($_POST['postal']) ||
empty($_POST['date']) ||
empty($_POST['time1']) ||
empty($_POST['time2']) ||
empty($_POST['phone']))
{
$errors .= "\n Error: fields with a * are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$address = $_POST['address'];
$postal = $_POST['postal'];
if(!empty($_POST['unit'])){
$unit = $_POST['unit'];
}
$phone = $_POST['phone'];
$date = $_POST['date'];
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];
$itemsharp = $_POST['itemsharp'];
$itemrepair = $_POST['itemrepair'];
$comment = $_POST['comment'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Please provide a valid email address";
}
$captcha;
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the captcha form.</h2>';
exit;
}
$secretKey = "[mysecretkeyisfilledinhere]";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the #$%K out</h2>';
} else {
if( empty($errors))
{
$to = $myemail;
$email_subject = "Sharpening request: $name";
$email_body = "You have received a new sharpening request. ".
"From:\n Name: $name \n Email: $email_address \n Phone: $phone \n Address: $address $unit $postal \n \n Date: $date \n Between: $time1 and $time2 \n Items for sharpening: $itemsharp \n Items for repair: $itemrepair \n Comment: \n $comment ";
$headers = "From: request#sharpsteel.ca\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: requestthankyou.html');
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Request failed</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
Most of this is cobbled together from various sources. My php is not that strong.
I tested it when I first created it, it worked fine.
Now the site is live and.... nothing. Any attempt to submit the form leads to the "please check the captcha" error page. I didn't change a thing, which is why I'm getting a touch frustrated.
I've obscured the email address and secret key here, for obvious reasons.
I have looked at other questions but they're either not relevant (using different and unfamiliar to me languages) or I simply don't understand for which I do apologise.
Any help would be much appreciated.

There were definite markup issues with the html form- there were div tags breaking the form.
The markup below appears identical but rest assured the prder of the form and div tags has changed to ensure the form is vald.
<script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="contactform">
<form method="POST" name="contactform" action="contact-form-handler.php">
<div id="details">
<p>
<label for='name'>Full name *:</label>
<br>
<input type="text" name="name">
</p>
<p>
<label for='address'>Address *:</label>
<br>
<input type="text" name="address">
</p>
<p>
<label for='unit'>Unit:</label>
<br>
<input type="text" name="unit">
</p>
<p>
<label for='postal'>Postal code *:</label>
<br>
<input type="text" name="postal">
</p>
<p>
<label for='email'>Email:</label>
<br>
<input type="text" name="email">
</p>
<p>
<label for='phone'>Telephone *:</label>
<br>
<input type="text" name="phone">
</p>
<p>
<label for='date'>Preferred pickup date* :</label>
<br>
<input type="date" name="date">
</p>
<p>
<label for='time'>Preferred timeslot* :</label>
<br>
<span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span>
<br>
<input type="text" name="time1"> to
<input type="text" name="time2">
</p>
</div>
<div id="products">
<p>
<label for='itemsharp'>Items for sharpening:</label>
<br>
<textarea name="itemsharp"></textarea>
</p>
<p>
<label for='itemrepair'>Items for repair:</label>
<br>
<textarea name="itemrepair"></textarea>
</p>
<p>
<label for='comment'>Comment: </label>
<br>
<textarea name="comment"></textarea>
</p>
<div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div>
<input class="button" type="submit" value="Submit">
<br>
</div>
</form>
</div>

Related

After submiting a php form I get empty window and no e-mail

Update:
I've added echo $errors to the end of my code. Now I am getting that all fields are required although all are filled:
} else {
echo $errors;
}
I've created a simple php e-mail form with this example (link). And jQuery form validator (link).
Now what I get after submiting a form is just a empty "contact-form-handler.php" page.
You can see the form live at: mantasmilka.com/#contactPage
What could be the problem? Below is my code.
contact-form-handler.php
<?php
$errors = '';
$myemail = 'mantas#mantasmilka.com';//<-----Put Your email address here.
if(empty($_POST['infoname']) ||
empty($_POST['infocompany']) ||
empty($_POST['infoemail']) ||
empty($_POST['infophone']) ||
empty($_POST['infodescription'])
)
{
$errors .= "\n Error: all fields are required";
}
$jobtype = $_POST['jobtype'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$infoname = $_POST['infoname'];
$infocompany = $_POST['infocompany'];
$infoemail = $_POST['infoemail'];
$infophone = $_POST['infophone'];
if (isset($_POST['infodescription'])) {
$infodescription = $_POST['infodescription'];
}
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$infoemail))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Jobtype: $jobtype \n Budget: $budget \n Location: $location \n Name: $infoname \n Company: $infocompany \n E-mail: $infoemail \n Phone: $infophone \n ".
"Message \n $infodescription";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $infoemail";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
// header('Location: http://www.mantasmilka.com/index.php');
header('Location: index.php');
exit();
} else {
echo $errors;
}
?>
my form in index.php:
<form id="contactform" method="post" name="contact_form" action="contact-form-handler.php">
<div class="left">
<fieldset class="jobtype">
<legend>Job type</legend>
<input type="radio" name="jobtype" id="project" value="project" required>
<label for="project">Project</label>
<input type="radio" name="jobtype" id="part-time" value="part-time" >
<label for="part-time">Part-time</label>
<input type="radio" name="jobtype" id="full-time" value="full-time" >
<label for="full-time">Full-time</label>
</fieldset>
<fieldset class="budget">
<legend>Budget</legend>
<input type="radio" name="budget" id="budget5k" value="budget5k" required>
<label for="budget5k">5k € ></label>
<input type="radio" name="budget" id="budget10k" value="budget10k" >
<label for="budget10k">5k - 10k €</label>
<input type="radio" name="budget" id="budget15k" value="budget15k" >
<label for="budget15k">15k € <</label>
</fieldset>
<fieldset class="location">
<legend>Location</legend>
<input type="radio" name="location" id="locremote" value="locremote" required>
<label for="locremote">Remote</label>
<input type="radio" name="location" id="loclocal" value="loclocal" >
<label for="loclocal">Local with relocation</label>
</fieldset>
</div>
<div class="right">
<fieldset class="contactinfo">
<legend>Your Contact Info</legend>
<div class="input-holder">
<input type="text" name="infoname" id="infoname" value="" required data-validation="alphanumeric">
<label for="infoname">Name</label>
</div>
<div class="input-holder">
<input type="text" name="infocompany" id="infocompany" value="" required data-validation="alphanumeric">
<label for="infocompany">Company</label>
</div>
<div class="input-holder">
<input type="text" name="infoemail" id="infoemail" value="" required data-validation="email">
<label for="infoemail">E-mail</label>
</div>
<div class="input-holder">
<input type="text" name="infophone" id="infophone" value="" required data-validation="number">
<label for="infophone">Phone</label>
</div>
<div class="input-holder textarea">
<textarea name="infodescription" form="contact_form" rows="4" required></textarea>
<label for="infodescription">Message</label>
</div>
<div class="input-holder submit">
<input type="submit" name="submit" value="Submit" required/>
</div>
</fieldset>
</div>
</form>
text field should look like this don't put form tag in here
<textarea name="infodescription" rows="4" required></textarea>
in php make the if statement like this the first ( opens the if statement the last ) closes it and take not of how i used the other brackets
if(
(empty($_POST['infoname'])) ||
(empty($_POST['infocompany'])) ||
(empty($_POST['infoemail'])) ||
(empty($_POST['infophone'])) ||
(empty($_POST['infodescription']))
)
{
$errors .= "\n Error: all fields are required";
}
The efficient way to solve the problem is:
$('#contactform').submit(function(ev) {
ev.preventDefault();
if($('#infodescription').val() == '')
{
alert('Description is required');
return false;
}
//add other validation
this.submit(); // If all the validations succeeded
});
By this you can avoid the unwanted server load.

Email Form Submits successfully but I do not get the phone number field in the record

I am using a custom optin page with a form , While testing and in work,When I submit the form I get all the details on my email except the phone number , I do not see any problem with the codes , I tried diff things like changing the value and stuff but it did not work, Here is the form code
<div class="form fix ">
<p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
<form name="contactform" action="mail-script.php" method="POST">
<label for="fname">First Name:
<input type="text" name="fname" id="fname" />
</label><br>
<label for="lname">Last Name:
<input type="text" name="lname" id="lname" />
</label><br>
<label for="email">Email Address:
<input type="text" name="email" id="email" />
</label><br>
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
</label><br>
<label for="resort">Resort Name:
<input type="text" name="resort" id="resort" />
</label><br>
<label for="amount">Amount Owed? $:
<input type="number" name="amount" id="amount" />
<p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
If Paid Off Leave Zero, Else Put Amount</p>
</label><br>
<div class="checkbox">
<div class="check-text fix">
<p>I'm Considering To</p>
</div>
<div class="check-one fix">
<input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
<input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
<input type="checkbox" name="call" id="" value="rent "/> Rent It
</div>
<div class="check-two fix">
<input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
<input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
<input type="checkbox" name="call" id="" value="give"/> Give It Back
</div>
</div>
<p class="captcha">
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input id="submit" type="submit" value="" />
<p class="submit-text">Ensure all fields are completed and correct, allowing you more benefits, while preventing abuse of our data.</p>
</form>
</div>
</div>
This is the mail script which sends me the email
<?php
/* Set e-mail recipient */
$myemail = "**MYEMAIL**";
/* Check all form inputs using check_input function */
$fname = check_input($_POST['fname'], "Enter your first name");
$lname = check_input($_POST['lname'], "Enter your last name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$resort = check_input($_POST['resort']);
$amount = check_input($_POST['amount']);
$call = check_input($_POST['call']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
First Name : $fname
Last Name : $lname
E-mail: $email
Phone : $phone
Resort: $resort
Amount: $amount
Call : $call
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: index.html');
exit();
/* Functions we used */
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)
{
?>
if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
Here is the online url of the page
http://timesharesgroup.com/sell/index.html
You have two form elements with the same name. The second one overwrites the first one and you never receive it. You also forget your alternate phone number in your PHP code.
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="altphone" id="aphone" />
</label><br>
Your PHP:
$phone = check_input($_POST['phone']);
$altphone = check_input($_POST['altphone']);
Phone : $phone
Alt Phone : $altphone
Resort: $resort
Your alternative phone number is overwriting your phone number:
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
^^^^^ here
</label><br>
Changing the name for the alternative number should fix that.

PHP form redirecting to PHP file itself

I'm trying to get a contact form working, and I'm being redirected to the PHP file itself, and I'm not sure why. I'm fairly new to PHP and I'm not entirely sure what I'm doing wrong. I'd love to be pointed in the right direction. The code is below.
Thanks
HTML:
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
PHP:
<?php
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
?>
This line tells the form what PHP file to send the data to:
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
In particular, it is this part that sends the data to a particular form:
action="form.php"
In fact, this is fine. You can process a form in the same PHP file that contains the form. Just put the PHP form processing at the top:
<?php
if (isset($_POST['Email_Address'] && $_POST['Email_Address'] != ''){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
Just remove enctype="text/plain" otherwise your code is correct in HTML and try to echo feedback variable other way is to write all your code above the HTML like below:
<?php
if (isset($_POST['Email_Address'] && !empty['Email_Address']){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>

Can't get php contact form to work

I have a webpage that has two contact forms and the second one is working fine but I can't seem to get the first one to work. I am fairly new to php. Thanks in advance for the help. Here's the html:
<h3>Message Us</h3>
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<div id="msgbox1">
<label for="name2">Name:</label>
<input type="text" id="name2" name="name2" placeholder=" Required" />
<label for="email2">Email:</label>
<input type="text" id="email2" name="email2" placeholder=" Required" />
<label for="phone">Phone:</label>
<input type="text" id="phone" name="phone" placeholder="" />
<label for= "topic">Topic:</label>
<select id="topic" name="topic">
<option value="general">General</option>
<option value="stud">Property Price Enquiry</option>
<option value="sale">Bull Sale Enquiry</option>
</select>
</div><!--- msg box 1 -->
<div id="msgbox2">
<textarea id="message" name="message" rows="7" colums="25" placeholder="Your Message?"></textarea>
<p id="feedback2"><?php echo $feedback2; ?></p>
<input type="submit" value="Send Message" />
</div><!--- msg box 2 -->
</form><!--- end form -->
</div><!--- end message box -->
And here's the php:
<?php
$to2 = '418#hotmail.com'; $subject2 = 'MPG Website Enquiry';
$name2 = $_POST ['name2']; $email2 = $_POST ['email2']; $phone = $_POST ['phone']; $topic = $_POST ['topic']; $message = $_POST ['message'];
$body2 = <<<EMAIL
This is a message from $name2 Topic: $topic
Message: $message
From: $name2 Email: $email2 Phone: $phone
EMAIL;
$header2 = ' From: $email2';
if($_POST['submit']=='Send Message'){
if($name2 == '' || $email2 == '' || $message == ''){
$feedback2 = '*Please fill out all the fields';
}else {
mail($to2, $subject2, $body2, $header2);
$feedback2 = 'Thanks for the message. <br /> We will contact you soon!';
} } ?>
For the saveScrollPositions I use the following php and script:
<?php
$scrollx = 0;
$scrolly = 0;
if(!empty($_REQUEST['scrollx'])) {
$scrollx = $_REQUEST['scrollx'];
}
if(!empty($_REQUEST['scrolly'])) {
$scrolly = $_REQUEST['scrolly'];
}
?>
<script type="text/javascript">
window.scrollTo(<?php echo "$scrollx" ?>, <?php echo "$scrolly" ?>);
</script>
You have a mistake in your HTML part i.e.
<input type="submit" value="Send Message" />
add attribute name also in this input type like this-
<input type="submit" value="Send Message" name="submit" />
one thing more to correct in your php script is write-
$header2 = "From: ".$email2; instead of $header2 = ' From: $email2';
now try it.
What do you return in "saveScrollPositions" function? if you return false the form submit wont fire.

Contact form Error when submit

Hi guys i'm having a issue i hope you guys can help with, i'm typing in all the fields and then upon pressing submit i'm getting just "Error!" on my screen.
Please see the code:
HTML
<h2 class="formhead">Contact Form</h2>
<br>
<form class="form" action="mail.php" method="POST">
<p class="name">
<input type="text" name="name" id="name" placeholder="John Doe" />
<label for="name">Name</label>
</p>
<br>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" />
<label for="email">Email</label>
</p>
<br>
<p class="number">
<input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
<label for="name">Contact Number</label>
</p>
<br>
<p class="web">
<input type="text" name="web" id="web" placeholder="www.example.co.uk" />
<label for="name">Website</label>
</p>
<br>
<p class="message">
<textarea name="message" id="message" placeholder="Write something to us" /> </textarea>
</p>
<br>
<p class="submit">
<input type="submit" value="Send"/>
</p>
</form>
PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$website = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries#c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
Any help would be much appreciated!
Thanks
Sam
Your script always reporting 'Error!' because the mail() function always fails. That's because some index you're using in the php file doesn't match to the input names in your form:
Change these:
$website = $_POST['website'];
to:
$website = $_POST['web'];
Or change it in your form.
Also you have to specify a name for the message textarea:
<textarea name="message" id="message" placeholder="Write something to us" />
This may fail again if it can't connect to mailserver. This is probably you're case if The SMTP is Disabled.
As per my comment, here's an example of a better die statement:
<?
$your_function or die("Error! a") // Just replace the letter a with anything. It serves as a simple link to your function that only you know. so you can go back and check it

Categories