This question already has answers here:
How can I send an email using PHP?
(20 answers)
Can't send email with php mail function on windows 8
(8 answers)
Closed 5 years ago.
I am building a simple html website and i have to send the email from contact us form. I dont have any idea how to send mail using html. I am trying to send the mail using php in such a way succees message is shown but the mail is not receiving neither in inbox nor in spam. Is there any alternate to escape from php or is there any free api to send the mail.
here is php code .
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not 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,$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($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 .= "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 .= "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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
If I understand your issue correctly, you have a contact form on a page, which when it's filled in and submitted, should send an email to your inbox for you to deal with. If that's the case, I would truly recommend looking into https://formspree.io/. The way Formspree works, is instead of you handling the POST response, you send it straight to Formspree. They take the response, process it for you, and email you the contents straight away.
You will not have to worry about running a server or anything like that, and you'll be guaranteed to receive the emails all the time. Plus it's free for up to 1000 emails a month.
Try this code! I have tested and working!
create new file contact.php and add this to the file!
You can customize HTML/CSS later!
<?php
if(isset($_POST['submit'])){
$to = "email#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Related
So, this is my first attempt in PHP so it might be very easy to fix. I am trying to make a form which can be submitted and sent to administration's e-mail.
I am running a server with MAMP, going online filling the form, submitting it and I get error:
We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
We are sorry, but there appears to be a problem with the form you submitted.
Please go back and fix these errors.
Full PHP code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "I HAVE CORRECT EMAIL HERE 4 SURE";
$email_subject = "eShop Contact Form";
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['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['fname']; // required
$last_name = $_POST['lname']; // required
$email_from = $_POST['email']; // required
//$country = $_POST['country']; // not required
$comments = $_POST['subject']; // 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($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 .= "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 .= "Country: ".clean_string($country)."\n";
$email_message .= "Subject: ".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
}
?>
This is the part that should be having problem:
// validation expected data exists
if(!isset($_POST['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
P.S I have copied the code from http://www.freecontactform.com/email_form.php here and edited it a little.
Well, now I will start from here.
I will re-edit your code
SUBMIT.PHP
<?php
if(isset($_POST['formid'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "yourmail.com.id#maisetting.com";
$email_subject = "eShop Contact Form";
//
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comm'];
// I was replace this line
// validation expected data exists
if(empty($fname) or empty($lname) or empty($mail) or empty($subject) or empty($comments)){
$err_msg = 'We are sorry, but there appears to be a problem with the form you submitted.';
} else {
// check mail registered
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$mail)) {
$err_msg = 'The Email Address you entered does not appear to be valid.<br />';
} else {
// check name
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fname)) {
$err_msg = 'The First Name you entered does not appear to be valid.<br />';
} else {
// check Last name
if(!preg_match($string_exp,$lname)) {
$err_msg = 'The Last Name you entered does not appear to be valid.<br />';
} else {
// Check comment
if($comments<2 or $comments=='') {
$err_msg = 'The Comments you entered do not appear to be valid.<br />';
} else {
// SEND msg from the visitor
$err_msg = 'Your Messages Was Send. ThankYou!';
$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($fname)."\n";
$email_message .= "Last Name: ".clean_string($lname)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
// $email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "Subject: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}}}}} } else { $err_msg = 'Add Your comment here'; }
?>
INDEX.PHP
<?php require('SUBMIT.PHP'); ?>
<form action="#" method="post" />
<p><label>First Name</label>
<input type="text" placeholder="First name here" name="fname" />
</p>
<p><label>Last Name</label>
<input type="text" placeholder="Last name here" name="lname" />
</p>
<p><label>Mail</label>
<input type="text" placeholder="Add yourmail here" name="mail" />
</p>
<p><label>Subject</label>
<input type="text" placeholder="Subject here" name="subject" />
</p>
<p><label>Your Comment</label>
<textarea name="comm"></textarea>
</p>
<p><input type="submit" name="formid" value="Send" /></p>
</form>
<?php echo $err_msg; ?>
Now, do and test.
My online contact form submits correctly. However, when someone enters #gmail. as part of their email address, the submitted form does not arrive to me.
Puzzling because if #xgmail. or #gmailx. or #gmai. is entered, the submitted form does arrive. And it arrives to a hotmail account or gmail address or business address just the same, directly or via email client, inbox or other. And it's the same whether using Firefox, Chrome or IE.
I asked friends to try for me with the same result.
Problem is merely entering #gmail. in the email form field.
How can it be?
contact.html file:
<div>
<form action="contact.php" method="post">
<div>
<span>Email: (required)</span>
<label>
<input placeholder="Please enter your email address" type="email" name="email" required>
</label>
</div>
</form>
</div>
contact.php file:
<?php
if(isset($_POST['email']))
{
$email_to = "forms#archiveambition.com.au";
$email_subject = "Message to Archive Ambition";
function died($error)
{
echo "
// error message code
";
die();
}
if( !isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$error_message = "";
//EMAIL VALIDATE
$email_exp = "/^[A-Z0-9._-]+#[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
if(!preg_match($email_exp,$email_from))
{
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
//FIRST NAME
$string_exp = "/^[a-z.']+$/i";
if(!preg_match($string_exp,$first_name))
{
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
//MESSAGE COMMENTS
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 = "\nMessage details: \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 .= "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);
?>
Thank you.<br />
Your message has been sent.<br />
<?php
}
?>
Thanks.
Some servers are picky about who they will send mail from. I have experience with go daddy servers not sending mail when trying to use a from address not hosted by them.
instead of making the email from $_POST['email'] make it from no-reply#yourdomainname and include the from email in the body for your reference.
I know this means you can't directly reply to the email, but sometimes that's the way it is.
I'm working on a PHP mail form and for some reason only certain text doesn't send through. It has me baffled and I can't even think of how to Google an answer.
For example, if I enter for the form:
Name: Indiana Jones
Number: 000
Email: indiana#jones.com
The mail function won't work, however if I change the 000 to 999, it works.
OR if I change the indiana#jones.com to indiana#jones.net, it suddenly works too.
Here are snippers, from my HTML:
<form method="post" action="mail.php">
Name<br />
<input style="width:878px;" type="text" name="name" id="name" required>
Best Contact Number<br />
<input style="width:415px;" type="text" name="number" id="number" required>
Email<br />
<input style="width:415px;" type="email" name="email" id="email" required>
</form>
And from my PHP (mail.php): (personal email addresses have been removed)
<?php
ini_set("SMTP","mail.email.com.au");
ini_set('sendmail_from', 'email#email.com.au');
$to = "email#email.com.au";
$subject = "Mail Form";
$message = "Name:" . "\n" . $_POST['name'] . "\n\n";
$message .= "Best Contact Number:" . "\n" . $_POST['number'] . "\n\n";
$message .= "Email:" . "\n" . $_POST['email'] . "\n\n";
$headers = "From: Removed <email#email.com.au> \n";
if(#mail($to, $subject, $message, $headers))
{
echo "<script type='text/javascript'>alert('Thank you for your submission'); window.location.href = 'index.html';</script>";}
else
{
echo "<script type='text/javascript'>alert('There was an error - please check all fields and try again'); window.location.href = 'index.html';</script>";
}
?>
well, I just got a code that will make it work great .
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#email.com.au";
$email_subject = "Mail Form";
function died($error) {
// your error code can go here
echo "<script type='text/javascript'>alert('There was an error because '); window.location.href = 'index.html';</script>";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['number']) ||
!isset($_POST['email'])) {
died('<script type='text/javascript'>alert('There was an error - please check all fields and try again'); window.location.href = 'index.html';</script>');
}
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$number = $_POST['number']; // 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 Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 0) {
$error_message .= 'The Number 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($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Number: ".clean_string($number)."\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);
?>
<!-- if sent successfuly -->
<script type='text/javascript'>alert('Thank you for your submission'); window.location.href = 'index.html';</script>
<?php
}
?>
You can add this code to display the errors for users
echo $error."<br /><br />";
Sorry, it turns out this was an Exchange server issue. I have no idea why it was letting some messages go through and filtering others, but our IT team sorted it out and had to allow the website's IP through.
Form is fully functional now though!
So I have this form.
Its a very simple mail/newsletter form.
<form action="http://localhost/website/subscribe.php" method="POST" id="signup_form">
<label for="email"><p id = "subText">Subscribe</p></label>
<input type="text" name="email" size="30" class="required email txtEmail" placeholder = "Enter Email Address">
<input type="submit" value="Go" name="submit" class = "goButton"/>
</form>
and I have this subscribe.php file.
<?php
if(isset($_POST['email']))
{
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#email.com";
$email_subject = "Subscription";
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['email']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$email_from = $_POST['email']; // 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 />';
}
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 .= "Email: ".clean_string($email_from)."\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
}
?>
That I found here, I just edited it a bit to fit my form. I'm really new to PHP and I'm still in the practice phase.
The error I get is
PHP Parse error: syntax error, unexpected T_VARIABLE in /home/techstars05/www/website/subscribe.php on line 6, referer: http://localhost/website/index.html
I'm using sublime text 2 to edit the codes and I noticed that "if(isset($_POST['email']))"'s 'if' is of a different color from the other ifs from the subscribe.php file. Its pink while the others are violet-ish. I'm not really sure what does mean, I tried tracing the code but to my newbie eyes it looks quite fine.
TIA
give this a try :
<?php
if(isset($_POST['email'])) {
//email is set
$email_from = $_POST['email'];
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$email_from)) {
//email data
$email_from = $_POST['email'];
$email_to = "email#email.com";
$email_subject = "Subscription";
//create body
$email_message = "Form details below.\n\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
$headers .= 'Reply-To: '.$email_from."\r\n" .
$headers .= 'X-Mailer: PHP/' . phpversion();
if(mail($email_to, $email_subject, $email_message, $headers)){
echo "email sent successfully";
exit();
}else{
echo "email failed to send";
}
}else{
echo "email is not valid";
}
}else{
echo "email is not set";
}
function clean_string($string){
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
?>
I am trying to develop a simple contact form but the form is not sending any email and I do not know how to debug and how to solve this issue.
this is my plugin code:
<?php
/*
Plugin Name: Contact Form
Plugin URI: http://www.exmple.com/
Description: This plugin allows captcha for a contact form.
Version: 1.0
Author URI: http://www.example.com/
License: GPL2
*/
?>
<?php
function contact_shortcode_func( $atts, $content="" ) {
$content.="<div id='contact_form_errorloc' class='err'>".plugins_url()."</div>
<form method='POST' name='contact_form'
action='".str_replace( '%7E', '~', $_SERVER['REQUEST_URI'])."'>
<p>
<label for='name'>Name: </label><br>
<input type='text' name='name1' value=''>
</p>
<p>
<label for='email'>Email: </label><br>
<input type='text' name='email1' value=''>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name='message1' rows='8' cols='30'></textarea>
</p>
<input type='submit' value='Submit' name='submit'>
</form>";
return $content;
//echo $your_email ='xxxxx#gmail.com';// <<=== update to your email address
if(isset($_POST['submit']))
{
$your_email ='xxxxx#gmail.com'; //here i am using valid email id
$name = $_POST['name1'];
$visitor_email = $_POST['email1'];
$user_message = $_POST['message1'];
///------------Do Validations-------------
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"Name: $name\n".
"Email: $visitor_email \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
wp_mail($to, $subject, $body,$headers);
//header('Location: thank-you.html');
}
}
add_shortcode( 'cfwc', 'contact_shortcode_func' );
So any idea how to fix it.
Your mail functionality is written behind return of your function. This is code that is never reached.
Everything after return $content; will not be executed. Move your return to the end of your function.
Here is the complete working form you can take the help from this code, this can be include into html form as post.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "user#gmail.com";
$email_subject = "Your email subject line";
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not 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,$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($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 .= "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 .= "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);
?>
<!-- include your own success html here -->
<h4 align="center">Thank you for contacting us. We will revert you back.</h4>
<?php
}
?>