Would this work, i want to email the contents of my form to email@example.com, but when I run it in localhost it doesn't send, I am wondering if the results would be different online, I don't know why it wouldnt work online. I just want the name and message to be send in a email to the specified email address. When I send it there is no errors, and it does redirect me to the page that states thank you for contacting us.
<form name="contactform" method="post" action="send_form_email.php">
<input name="name" placeholder="Your Name"></input>
<br>
<textarea name="message" placeholder="Email Us." style="height:100px;"> </textarea>
<input type="submit" id="sub" value="Submit" placeholder="Submit" style=""></input>
</form>
<?php
if(isset($_POST['message'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email@example.com";
$email_subject = "Customer";
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();
}
if(!isset($_POST['message'])){
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$message = $_POST['message']; // 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 .= 'The Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$message)) {
$error_message .= 'The message you entered does not appear to be valid.<br />';
}
$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 .= "Message: ".clean_string($message)."\n";
'X-Mailer: PHP/' . phpversion();
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>