I am unsure why my contact form is not working, it uses html and php but I can not for the life of me work out whatI have done wrong for it not to work. I have done weeks and weeks of research and experiments and still nothing. I would be very grateful if somebody could point me in the correct direction. Thank you, my code is below
HTML
<form method="POST" name="contactform" action="contact-form-handler.php">
<p align="center">
<label for='name'><FONT color="#FFFFFF" SIZE=2>YOUR NAME:</FONT></label>
<font color="#FFFFFF">
<input name="name" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='telephone'><FONT SIZE=2>TELEPHONE:</FONT></label>
<input name="telephone" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='email'><FONT SIZE=2>EMAIL:</FONT></label>
<input name="email" type="text">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='budget'><FONT SIZE=2>BUDGET:</FONT></label>
<input name="budget" type="text" id="finish">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='location'><FONT SIZE=2>LOCATION:</FONT></label>
<input name="location" type="text" id="location">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='service'><FONT SIZE=2>SERVICE:</FONT></label>
<select id="service" name="service">
<option value="000">Pick Service</option>
<option>Resealing</option>
<option>Toilet Plumbing</option>
<option>Boiler Work</option>
<option>Exterior Plumbing</option>
</select>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='message'><FONT SIZE=2>INFO:</FONT></label>
<textarea name="message"></textarea>
</font></p>
<div align="center">
<font color="#FFFFFF">
<input type="submit" value="SUBMIT">
</font></div>
</form>
PHP1 contact-form-handler
<?php
$errors = '';
$myemail = 'david#mildenhire.com';
if(empty($_POST['name']) ||
empty($_POST['telephone']) ||
empty($_POST['email']) ||
empty($_POST['budget']) ||
empty($_POST['location']) ||
empty($_POST['service']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email_address = $_POST['email'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$service= $_POST['service'];
$message = $_POST['message'];
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: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Free Quote: $name";
$email_body = "You have received a new free quote request. ".
" Here are the details:\n Name: $name \n Telephone: $telephone \n Email: $email_address \n Budget: $budget \n Location: $location \n Service: $service \n Message: \n $message";
$headers = "From: $email_address \n";
$headers .= "Reply-To: $email_address \n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thankyou.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Big Smile Free Quote Request</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
PHP 2 contactformprocess.php
<?php
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['first_name']; // required
$email_from = $_POST['last_name']; // required
$telephone = $_POST['email']; // required
$comments = $_POST['telephone']; // required
$antispam = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$email)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($first_name) < 2) {
$error_message .= 'Your First Name does not appear to be valid.<br />';
}
if(strlen($last_name) < 2) {
$error_message .= 'Your Last Name does not appear to be valid.<br />';
}
if(strlen($email) < 2) {
$error_message .= 'Your E-mail does not appear to be valid.<br />';
}
if(strlen($telephone) < 2) {
$error_message .= 'Your Telephone Number does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\r\n";
$email_message .= "Last Name: ".clean_string($last_name)."\r\n";
$email_message .= "E-Mail: ".clean_string($email)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
I know this is a fair bit to read through but it doesn't take long as it is mostly PHP Script.
I hope you can help me you wonderful people
Perhaps it is just a problem of SMTP configuration.
Since you get no error, I assume the function mail() is correctly called, but if your server is not properly configured for sending emails, you can't receive anything.
My advice would be to take a look at your webserver configuration (you're probably using something like WAMP or EasyPHP).
Related
<form name="contactform" method="post" action="send_form_email.php">
<!--Name input-->
<input placeholder="Full Name *" type="text" name="name" maxlength="50">
<br />
<!--Email input-->
<input placeholder="Email Address *" type="email" name="email" maxlength="80">
<br />
<!--Phone number input (not required)-->
<input placeholder="Telephone Number" type="tel" name="telephone" maxlength="15">
<br />
<!--Company name input (not required)-->
<input placeholder="Company" type="text" name="company" maxlength="50">
<br />
<!--Comments & messege input-->
<textarea placeholder="Please include as much information as possible *" name="comments" maxlength="500" cols="25" rows="5"></textarea>
<br />
<!--Check for privacy policy-->
<label class="GDRP">
I consent to having this website store my submitted information so they can respond to my inquiry.
<input type="checkbox" name="GDRP">
</label>
<!--Submit button-->
<input type="submit" value="SUBMIT">
</form>
This is my HTML - I don't know how important it is to helping me find a solution but I figured, why not. I tried cleaning it up so you can get through with helping me as quick as possible. The only important fields are the 'name', 'email', 'comments' and the question at matter 'GDRP'.
<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#adress.com";
$email_subject = "www.Adress.com - CONTACT FORM";
function died($error) {
// error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted: ";
echo $error."<br />";
echo "Please fix these errors.";
die();
}
// validation expected data exists
if(
!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['company']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments']) ||
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$company = $_POST['company']; // not required
$comments = $_POST['comments']; // required
$GDRP = $_POST['GDRP']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= '<br /><br /><font color="red">Full Name</font><br /><br />';
}
if(!preg_match($email_exp,$email_from)) {
$error_message .= '<font color="red">Email Address</font><br /><br />';
}
if(strlen($comments) < 2) {
$error_message .= '<font color="red">Comments</font><br /><br />';
}
if(!empty($GDRP)) {
$error_message .= '<font color="red">GDRP Agreement</font><br /><br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<body>
Thank you for contacting us. We will be in touch with you as soon as possible.
</body>
<?php
}
?>
My problem is that the checkbox ('GDRP') isn't showing $error_message when it's not filled in. In fact, none show when 'GDRP' is empty. If you fill 'GDRP' but leave the others [required fields] empty all of their $error_message except for 'GDRP' will show.
if(!empty($GDRP)) { // if not empty
$error_message .= '<font color="red">GDRP Agreement</font><br /><br />';
}
looks like you are checking that $GDPR isn't empty, this should be the other way around.
change if(!empty($GDRP)) { to if(empty($GDRP)) {.
Only checked checkboxes send and available in POST. So, looks like in the following lines your script finished and other errors not shown:
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
i"m new here and i don't understand php at all, but i need to do a contact form with checkbox and verification, this is my code ( is a frankenstein code).
I need that my form send an email with the information avoiding spam, and missing information, and when mail arrive has all the details in header like a mail to reply, subject and all.
if you can post an correct code will be wonderful.
thanks in advance
<form name="htmlform" method="post" action="app.php">
<label for="name">*Nombre Completo</label>
<input type="text" name="name" maxlength="150" size="50">
<label for="company">*Empresa</label>
<input type="text" name="company" maxlength="150" size="50">
<label for="telephone">Teléfono</label>
<input type="text" name="telephone" maxlength="150" size="50">
<label for="email">*Email</label>
<input type="text" name="email" maxlength="180" size="50">
<label for="services">*Servicios de Interes</label>
<input type="checkbox" name="services[]" value="apps" />apps<br />
<input type="checkbox" name="services[]" value="Marketing Movil" />Marketing Móvil<br />
<input type="checkbox" name="services[]" value="video juegos" />video Juegos<br />
<label for="comments">*Comentarios</label>
<textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea>
<div class="hide">Leave this empty:<input name="url" /></div>
<center><input class="button large" type="submit" value="Submit Form"></center>
</form>
<?php
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == '')
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "my#mail.com";
$email_subject = "Contact from web.com";
function died($error) {
// your error code can go here
echo "There were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['full_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['services']) ||
!isset($_POST['comments']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$full_name = $_POST['full_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$services = $_POST['services']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$full_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($full_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Services: ".clean_string($services)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
// hacker defense
function clean($var){//request string cleaner
if(get_magic_quotes_gpc()) $var=stripslashes($var); //clean
$var=mysql_real_escape_string($var); //clean
return strip_tags($var, '<b><a>');//returning clean var
}
function hackerDefense(){//thanks to Allen Sanford
// begin hacker defense
foreach ($_POST as &$postvalue){ //checking posts
$postvalue = clean($postvalue);//cleaning the value
}
} // end hacker defense
?>
<!-- include your own success html here -->
<center>
<img src="images/logo.png" />
<br>
<br>
Thank you for contacting us. We will be in touch.<br>
<br>
HOME</center>
<?php
}
?>
My form doesn't generate an E-Mail it just redirects me to a blank page.
i have my .php form in a folder named php on my server
thank you for your help.
here is my html code
<form id="form" method="post" action="php/send_form_email.php">
<fieldset>
<label><strong>Name:</strong>
<input type="text" value="">
</label>
<label><strong>Email:</strong>
<input type="text" value="">
</label>
<label><strong>Phone:</strong>
<input type="text" value="">
</label>
<label><strong>Message:</strong>
<textarea></textarea>
</label>
<div class="btns">ClearSend</div>
</fieldset>
</form>
here is the php code i'm using:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "###.com";
$email_subject = "havok security contact form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there was an error found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not required
$comments = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($telephone)."\n";
$email_message .= "Message: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
The input type under email needs to have a name attribute called "email". Your PHP script is looking to see if $_POST["email"] is set, and it is not. So, this should work:
<form id="form" method="post" action="php/send_form_email.php">
<fieldset>
<label><strong>Name:</strong>
<input type="text" name="name" value="">
</label>
<label><strong>Email:</strong>
<input type="text" name="email" value="">
</label>
<label><strong>Phone:</strong>
<input type="text" name="phone" value="">
</label>
<label><strong>Message:</strong>
<textarea name = "message"></textarea>
</label>
<div class="btns">ClearSend</div>
</fieldset>
</form>
Hi All i am trying to get my contacts page working i have input all the date but when i click on submit it just displays the php code on the next page. WHat am i doing wrong.
HTML Code:
<form method="post" name="contact" action="php\html_form_send.php">
<label for="name">Name:</label> <input type="text" id="name" name="name" class="required input_field" />
<div class="cleaner h10"></div>
<label for="email">Email:</label> <input type="text" id="email" name="email" class="validate-email required input_field" />
<div class="cleaner h10"></div>
<label for="telephone">Telephone:</label> <input type="number" name="telephone" id="telephone" class="input_field" />
<div class="cleaner h10"></div>
<label for="subject">Subject:</label> <input type="text" name="subject" id="subject" class="input_field" />
<div class="cleaner h10"></div>
<label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner h10"></div>
<input type="submit" value="Send" id="submit" name="Submit" class="submit_btn float_l" />
<input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
</form>
PHP Code:
<body>
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "info#*********.com";
$email_subject = "website html form submissions";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['subject']) ||
!isset($_POST['text'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$subject = $_POST['subject']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$text = $_POST['text']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$subject)) {
$error_message .= 'The subject you entered does not appear to be valid.<br />';
}
if(strlen($text) < 2) {
$error_message .= 'The text you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Last Name: ".clean_string($subject)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "text: ".clean_string($text)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
</body>
ERROR
"; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['subject']) || !isset($_POST['text'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $subject = $_POST['subject']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $text = $_POST['text']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$subject)) { $error_message .= 'The subject you entered does not appear to be valid.
'; } if(strlen($text) < 2) { $error_message .= 'The text you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($name)."\n"; $email_message .= "Last Name: ".clean_string($subject)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "text: ".clean_string($text)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); #mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon.
The PHP code is not beeing compiled. It's been served as a plain file. Check your PHP installation.
Someone please help me with my code everything seems to be fine but, when ever I click the Submit button the browser displays the PHP scripts instead of Sending the email to my mail account. PHP is installed I thought that was the problem. please help?????? here is my PHP script
<?php
if(isset($_POST['submit'])) {
$email_to = "example#domain.com";
$email_subject = "Wedding Wishes";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['txtName']) ||
!isset($_POST['txtSurname']) ||
!isset($_POST['txtEmail']) ||
!isset($_POST['txtRegion']) ||
!isset($_POST['cmbRelation']) ||
!isset($_POST['txtMessage'])) {
died('We are sorry, but there appears to be a problem with the form you');
}
$first_name = $_POST['txtName']; // required
$last_name = $_POST['txtSurname']; // required
$email_from = $_POST['txtEmail']; // required
$region = $_POST['txtRegion'];
$relation = $_POST['txtRelation'];// not required
$message = $_POST['txtMessage']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Region: ".clean_string($region)."\n";
$email_message .= "Relation: ".clean_string($relation)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
And my Html form is as follows.
<div class="grid_16" style="width:400px;">
<div class="top-1">
<form id="form" method="post" action="SendEmail_Wishes.php" style="width: 400px;" >
<fieldset>
<p>
<label><strong>Name:</strong>
<input type="text" name="txtName" style= "width:300px; height:25px;">
<strong class="clear"></strong></label>
<label><strong>Surname:</strong>
<input type="text" name="txtSurname" style= "width:300px; height:25px;">
<strong class="clear"></strong></label>
<label><strong>Email:</strong>
<input name="txtEmail" type="text" style= "width:300px; height:25px;">
<strong class="clear"></strong></label>
<label><strong>Region:</strong>
<input name="txtRegion" type="text" id="txtRegion" value="Country & City" >
<strong class="clear"></strong></label>
<label><strong>Relation:</strong>
<select name="cmbRelation" id="cmbRelation" accesskey="2" tabindex="2">
<option value="Family">Family</option>
<option value="Friend" selected>Friend</option>
</select>
<br>
</label>
<label><strong>Message:</strong>
<textarea name="txtMessage" id="txtMessage" style= "width:300px;"></textarea>
<font size="1"><br />
<br />
<br />
<br />
<br />
<br />
(Maximum characters: 250)<br>
<input name="submit" type="submit" value="submit" style="width:50px;">
<br />
<strong class="clear"></strong></label>
</p>
<script type="text/javascript">
function blank(a) { if(a.value == a.defaultValue) a.value = ""; }
function unblank(a) { if(a.value == "") a.value = a.defaultValue; }
</script>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
</fieldset>
</form>
You don't close the if(isset($_POST['submit'])) statement.
You are missing } at the end.
You server does not seems to be configured correctly.
I recommend before trying to send an email in php to make work an hello world example :
<?php
echo phpinfo();
?>
Try to call directly your page from your browser before using any html page.
Download SMTP server, run the server before you click submit.