I was just wondering if anybody could please help if this PHP code would work for validating HTML contact form inputs. I followed a tutorial to create this PHP validation, but i'm not sure if it will work. I don't have a webhost yet to test it out, but if anybody has a server,I will really be appreciated if anybody could do me a favour & try the code if you can send/receive email. Thank you!!
I'm using jQuery Validation Plugin for validating the form on client-side and this is the tutorial http://www.youtube.com/watch?v=rdsz9Ie6h7I
HTML form:
<form action="contact.php" method="post">
<label for="yourname">Your Name:</label>
<input type="text" name="YourName"/>
<label for="youremail">Your Email:</label>
<input type="text" name="YourEmail" />
<label for="yourmessage">Your Message:</label>
<textarea name="YourMessage"></textarea>
<fieldset>
<input type="submit" id="submit" value="Send"/>
<input type="reset" id="reset" value="Reset"/>
</fieldset>
PHP Code:
<?php
/* Subject and Email Variables */
$emailSubject = 'Email from site visitor';
$webMaster = 'YourEmail#mail.com';
/* Getting Form Data Variables */
$nameField = $_POST['YourName'];
$emailField = $_POST['YourEmail'];
$messageField = $_POST['YourMessage'];
$body = <<<EOD
<br><hr><br>
Name: $YourName <br>
Email: $YourEmail <br>
Message: $YourMessage <br>
EOD;
$headers = "From: $YourEmail\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
<html>
<head>
</head>
<body>
<p style="font-size:12px;font-family:Tahoma,Verdana;">Thanks for your Message.</p>
</body>
</html>
EOD;
echo "$theResults";
?>
If you don't have a webserver right now you can install a local one and test it there. Completly free.
http://www.apachefriends.org/en/xampp-windows.html#641
/* Getting Form Data Variables */
$nameField = $_POST['YourName'];
$emailField = $_POST['YourEmail'];
$messageField = $_POST['YourMessage'];
$body = <<<EOD
<br><hr><br>
Name: $nameField<br>
Email: $emailField <br>
Message: $messageField <br>
Lots of issues
You're not validating at all on the PHP side. I added validation and conditional rendering of success or failure messages below
You're not using the retrieved variable names (instead using $YourEmail) - the post names
Your form labels don't match the input names
Your form element isn't closed, and your fields aren't all in the fieldset, and the fieldset has no legend.
On case of failure, I added a value prefill in the form, so people don't get returned to a blank form when it falls to submit.
To do that, I put the form at the end, after the PHP
Code:
(Note: This would all be put into the file contact.php)
<?php
if (isset($_POST['submit'])) {
/* Getting Form Data Variables */
$nameField = isset($_POST['YourName']) ? $_POST['YourName'] : null;
$emailField = isset($_POST['YourEmail']) ? $_POST['YourEmail'] : null;
$messageField = isset($_POST['YourMessage']) ? $_POST['YourMessage'] : null;
// Validate
$failures = array();
if (strlen($nameField)) $failures[] = "Name is required";
if (strlen($emailField)) $failures[] = "Email is required";
if (filter_var($email,FILTER_VALIDATE_EMAIL) === false) $failures[] = "Email is invalid";
if (strlen($messageField)) $failures[] = "Message is required";
// If validation errors, render them
if (count($failures)) {
echo "<p><b>Failed to submit: " . implode(", ", $failures) . "</b></p>";
} else {
/* Subject and Email Variables */
$emailSubject = 'Email from site visitor';
$webMaster = 'YourEmail#mail.com';
$body = <<<EOD
<br><hr><br>
Name: {$nameField} <br>
Email: {$emailField} <br>
Message: {$messageField} <br>
EOD;
$headers = "From: {$emailField}\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
<p>Thanks for your Message.</p>
EOD;
echo "$theResults";
}
}
?>
<form action="contact.php" method="post">
<fieldset>
<legend>Contact Us</legend>
<label for="YourName">Your Name:</label>
<input type="text" name="YourName" value="<?=$nameField?>" />
<label for="YourEmail">Your Email:</label>
<input type="text" name="YourEmail" value="<?=$emailField?>" />
<label for="YourMessage">Your Message:</label>
<textarea name="YourMessage"><?=$messageField?></textarea>
<input type="submit" id="submit" value="Send"/>
<input type="reset" id="reset" value="Reset"/>
</fieldset>
</form>
Related
I'm a newbie to php and html, I've created a form which will accept the inputs from user and will send it to a specified Email id. Everything is working fine but on submitting the form, it goes to another new page.
How this can be replaced with a dialog box as a confirmation message upon submitting the form?
HTML -
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
PHP -
<?php
$errors = '';
$myemail = 'mymail#gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$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 = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name : $name \n Email : $email_address \n Message : $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "Your Message successfully sent, we will get back to you ASAP.";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
You can submit the form in the same page and can simply show JavaScript alert message to the users.
Below code will help you resolving your issue.
<?php
if(isset($_POST['btnSubmit'])){
$errors = '';
$myemail = 'mymail#gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$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 = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name : $name \n Email : $email_address \n
Message : $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
//echo "Your Message successfully sent, we will get back to you ASAP.";
}
print("<script>alert('Your Message successfully sent, we will get back to
you ASAP.');</script>");
}
?>
<form method="POST" name="contactform" action="">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit" name="btnSubmit"><br>
</form>
Hope it helps!
It can be done with following jQuery function:
$(document).ready(function() {
$("[name='contactForm']").submit(function() {
if(confirm("You are about to submit the form. Are you sure?")){
window.location = "http://www.google.com/"
};
});
});
But you will be redirected to a blank new page anyways. In order to prevent that you can either use an AJAX submit(simply add AJAX construction inside the function) or do the redirect using JavaScript function I added to jQuery script
My hosting provider has contacted me and said one of the sites I have designed is sending spoof emails. Done a little bit of research but I still don't really understand how/what are they are doing to send these spoof emails. However more importantly how should I approach this, would it help if I try and put one of these 'captcha' things in place on the contact form or should I change the code I have on my site. Which is shown below:
<?php
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "***";
$Subject = "Message to A R C Products";
$Name = Trim(stripslashes($_POST['Name']));
$Address = Trim(stripslashes($_POST['Address']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Message = Trim(stripslashes($_POST['Message']));
// prepare email body text
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$Message = "
Name:$Name
Address: $Address
Telephone: $Telephone
$Message";
// send email
$success = mail($EmailTo, $Subject, $Message, $headers);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
<h2><strong>Contact Us</strong></h2>
<form method="POST" action="contact.php">
<br/>
<p style="margin-top: 0;">Fields marked (*) are required</p>
<p style="margin-top: 0;">Your Email:* <br/>
<input type="text" name="EmailFrom">
<p style="margin-top: 0;">Name:* <br/>
<input type="text" name="Name">
<p style="margin-top: 0;">Address:<br/>
<input type="text" name="Address">
<p style="margin-top: 0;">Telephone:<br/>
<input type="text" name="Telephone">
<p style="margin-top: 0;">Message:*<br/>
<TEXTAREA NAME="Message" ROWS=6 COLS=40>
</TEXTAREA>
<p style="margin-top: 0;"><input type="submit" name="submit" value="Submit">
</form>
Take a look on filter_input to clean your input data. Also i would not use the email from the form as a from address.
$EmailFrom = filter_input(INPUT_POST,'EmailFrom', FILTER_SANITIZE_EMAIL);
I've created an HTML5 form, which incorporates reCAPTCHA, and I've also written a PHP script that sends an email when the form is submitted. At the moment, the script redirects the user to an error or thankyou page, but I'm trying to adjust it to dynamically replace the form within a message within the same page.
I've tried the following script, but it displays the message as soon as the page loads, before any user interaction.
PHP/HTML:
<?php
if ($_POST) {
// Load reCAPTCHA library
include_once ("autoload.php");
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$message = Trim(stripslashes($_POST['message']));
$emailFrom = $email;
$emailTo = "my#email.com";
$subject = "Contact Request";
// Prepare email body text
$body = "<strong>Name:</strong> $name <br /> <strong>Email:</strong> $email <br /> <strong>Message:</strong> $message";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";
$secret = 'XXX';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR']);
echo 'Your message was submitted!';
} else {
?>
<div class="contact-form">
<form role="form" method="post" action="index.php">
<label for="name"><span>Name</span><input type="text" class="input-field" name="name" required data-errormessage-value-missing="Please enter your name." /></label>
<label for="email"><span>Email</span><input type="email" class="input-field" name="email" required data-errormessage-value-missing="Please enter your email address." /></label>
<label for="message"><span>Message</span><textarea name="message" class="textarea-field" required data-errormessage-value-missing="Please enter your message."></textarea></label>
<label><span> </span><div id="recaptcha"><div class="g-recaptcha" data-sitekey="6LcBawsTAAAAAKBPfGs1jApXNRLvR2MIPng0Fxol"></div></div></label>
<label><span> </span><input type="submit" value="" class="submit-button" /></label>
</form>
</div>
<?php
}
?>
I'm new to PHP, so I'm not sure if it's a syntax or semantics issue. Any help would be greatly appreciated!
Here's one way of doing it.
Check to see if the form has been submitted with if(isset($_POST['submit'])). You can also use if($_SERVER['REQUEST_METHOD'] == 'POST') to see if the form has been submitted.
Then we check if the email has been successfully sent, and if it has we set the $success_message variable.
We then check to see if the $success_message variable is set, and if it isn't, we show the form.
Also, note that I added name="submit" to the submit button element. This is how we're checking to see if the form has been submitted.
I also changed stripslashes() to strip_tags() to prevent any malicious code from getting through.
<?php
// Load reCAPTCHA library
include_once ("autoload.php");
if(isset($_POST['submit'])) {
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = trim(strip_tags($_POST['message']));
$emailFrom = $email;
$emailTo = "my#email.com";
$subject = "Contact Request";
// Prepare email body text
$body = "<strong>Name:</strong> $name <br /> <strong>Email:</strong> $email <br /> <strong>Message:</strong> $message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";
$secret = 'XXX';
$lang = 'en';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR']);
// EDIT: repositioned recaptcha from OP's PasteBin script, as requested and adjusted messaging
// changed $success var to $message and added error message
// Original if statement, which redirected the user
if($resp->isSuccess()){
// send the email
if(mail($emailFrom, $subject, $body, $headers)) {
// set the success message
$success_message = 'The form was sent! Yay!';
} else {
// error message
$error_message = 'Could not send email';
}
} else {
$error_message = 'Prove you are a human!';
}
}
?>
<div>
<!-- quick and dirty way to print messages -->
<?php if(isset($success_message)) { echo $success_message; } ?>
<?php if(isset($error_message)) { echo $error_message; } ?>
</div>
<?php if(!isset($success_message)): ?>
<div class="contact-form">
<form role="form" method="post" action="index.php">
<label for="name"><span>Name</span><input type="text" class="input-field" name="name" required data-errormessage-value-missing="Please enter your name." /></label>
<label for="email"><span>Email</span><input type="email" class="input-field" name="email" required data-errormessage-value-missing="Please enter your email address." /></label>
<label for="message"><span>Message</span><textarea name="message" class="textarea-field" required data-errormessage-value-missing="Please enter your message."></textarea></label>
<div class="g-recaptcha" data-sitekey="6LcBawsTAAAAAKBPfGs1jApXNRLvR2MIPng0Fxol"></div>
<script type="text/javascript"
src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>">
</script>
<label><span> </span><input type="submit" name="submit" value="" class="submit-button" /></label>
</form>
</div>
<?php endif; ?>
I am a beginner in PHP and HTML and basically what I want to do is to have a few textboxes, and after the Submit button is pressed, the text introduced in those textboxes I want to be saved in a text file or to be sent to an email address. Can you help me out? I really have no idea about how to get this project started.
Thank you!
Copy paste and see the result
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style>
</style>
</head>
<body>
<form method="post">
<pre>
Name <input type="text" name="name">
</pre>
<pre>
Email <input type="text" name="email">
</pre>
<pre>
<input type="submit" value="Submit" name="submit">
</pre>
</form>
</body>
</html>
<?php
$to = "somebody#example.com";
$subject = "Subject of your email goes here";
$txt = "Body of your email goes here!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
if($name != '' || $email != ''){
mail($to,$subject,$txt,$headers); // Here your email is being sent.
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); // Here your file is being opened if it doesn't exist so it will create it first
fwrite($myfile, "Name :".$name." "."Email:". $email); // Here we are wirting file Name and email from the textboxes
fclose($myfile);//closing the file
}
}
?>
you should try something and after that come here if you have any issue . any way I can tell you some ways to do this
here are some links by which you can create a simple php form with email sending link 1 link2 link 3 link form
to enter the content into file read here
basicaly the code is
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("youremail#yoursite.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
code to put content into file is
<?php
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
?>
this may help you to start
<form name=myform method=post action="same_page.php">
<input type="text" name=username value="<?php echo $_POST['username'] "?>
<input type="text" name=email value="<?php echo $_POST['email']?> >
<input type="submit" value=submit>
</form>
<?php
$username = $_POST["username"]; //Email address you want it to 'appear' to come
$email = $_POST["email"];
if(strlen($username) && strlen($email))
{
$mailText ="The Contact Details: <br>";
}
$mailText=$mailText."<table border=1 cellspacing=0 cellpadding=0>";
while(list($Key, $Val)= each($_POST))
{
$mailText=$mailText."<tr><td width=50%>";
$mailText=$mailText."<b>".$Key."</b></td>";
$mailText=$mailText."<td width=50%>";
$mailText=$mailText.$Val;
$mailText=$mailText."</td></tr>";
}
$to = "youremailid.com";
if(strlen($username) && strlen($email))
{
$subject = "your subject"; //Subject Line
$headers .= "From:yourmail.com\n";
$headers .= "X-Sender: yourheader.com\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
$mailforms = mail($to, $subject, $mailText, $headers);
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I copied the message form and PHP mail from a website. But it doesn't seem to work. It does not send anything or make any reaction. I tried to find the error, but I am not familiar with PHP. I tried editing the $emailFrom =... to $_POST['email']; but that doesn't work either..
HTML:
<div id="form-main">
<div id="form-div">
<form class="form" id="form1">
<p class="name">
<input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Naam"/>
</p>
<p class="email">
<input name="email" type="text" class="validate[required,custom[email]] feedback-input" placeholder="E-mail" />
</p>
<p class="text">
<textarea name="text" class="validate[required,length[6,300]] feedback-input" placeholder="Bericht"></textarea>
</p>
<div class="submit">
<input type="submit" value="Verstuur" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
</div>
</div>
PHP:
<?php
include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);
//your email adress
$emailTo ="lisa-ederveen#hotmail.com"; //"yourmail#yoursite.com";
//from email adress
$emailFrom =$_POST['email']; //"contact#yoursite.com";
//email subject
$emailSubject = "Mail from Porta";
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;
if (!preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;
if($comment == "")
$data['success'] = false;
if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}
}
?>
Your form was incomplete, it missed the method (POST) and action (your php filename)
Try this instead:
<div id="form-main">
<div id="form-div">
<form action="sendEmail.php" method="POST" class="form" id="form1">
<p class="name">
<input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Naam"/>
</p>
<p class="email">
<input name="email" type="text" class="validate[required,custom[email]] feedback-input" placeholder="E-mail" />
</p>
<p class="text">
<textarea name="comment" class="validate[required,length[6,300]] feedback-input" placeholder="Bericht"></textarea>
</p>
<div class="submit">
<input type="submit" value="Verstuur" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
</div>
</div>
sendEmail.php
<?php
//include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
//$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
//$_POST = multiDimensionalArrayMap('cleanData', $_POST);
//your email adress
$emailTo ="lisa-ederveen#hotmail.com"; //"yourmail#yoursite.com";
//from email adress
$emailFrom =$_POST['email']; //"contact#yoursite.com";
//email subject
$emailSubject = "Mail from Porta";
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;
if (!preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;
if($comment == "")
$data['success'] = false;
if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}
}
?>
Firstly, your form: <form class="form" id="form1">
Forms default to GET if a method isn't specifically instructed.
Use POST like this if your HTML form and PHP are inside the same file:
<form class="form" id="form1" method="post">
since you are using POST arrays.
or
<form class="form" id="form1" method="post" action="your_handler.php">
if using a different file; I used your_handler.php as an example filename.
Also, <textarea name="text"...
that should be <textarea name="comment" as per your $_POST["comment"] array.
Using error reporting would have trigged an Undefined index text... notice.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
Footnotes:
I have no idea what multiDimensionalArrayMap('cleanEvilTags' does, so you'll have to check that.
If you're still not receiving mail, check your Spam.
Doing:
if(mail($emailTo, $emailSubject, $message, $headers)){
echo "Mail sent.";
}
and if it echoes "Mail sent", then mail() would have done its job. Once it goes, it's out of your hands.
You could look into using PHPMailer or Swiftmailer which are better solutions, as is using SMTP mailing.
Now, if (!empty($_POST)){ that isn't a full solution. It is best using a conditional !empty() for all your inputs. Your submit counts as a POST array and should only be relied on using an additional isset() for it.
If you're using this from your own computer, make sure that you've a Webserver installed. We don't know how your script is being used.
If you are using it from your own machine, make sure that PHP is indeed running, properly installed and configured, including any mail-related settings.
Additional notes:
You should also use full and proper bracing for all your conditional statements.
This has none:
if($comment == "")
$data['success'] = false;
which should read as
if($comment == ""){
$data['success'] = false;
}
Same thing for:
if($name == "")
$data['success'] = false;
Not doing so, could have adverse effects.
"I copied the message form and PHP mail from a website."
Again, about multiDimensionalArrayMap('cleanEvilTags'; if you don't have that function, then you will need to get rid of it and use another filter method for your inputs.
Consult the following on PHP.net for various filter options:
http://php.net/manual/en/filter.filters.php
http://php.net/manual/en/function.filter-input.php
http://php.net/manual/en/function.filter-var.php