i am not running this locally, i am running/debugging the issue live
what i mean is, a lot of the examples ive seen seem to have too much markup in them. i am trying to accomplish implementing a simple contact form, and my PHP seems to run just fine, it displays the alert on submit, but its not sending the email. I am not sure if its due to my PHP, but it seems to compile just fine.
Is there an issue with the way these 2 are wiring up?
HTML snip:
<form id="contactForm" class="" role="form" method="post" action="contactHandler2.php">
<input id="name" type="text" placeholder="NAME" name="name">
<input class="input-twin" id="email" name="email" type="text" placeholder="E-MAIL">
<input type="tel" class="input-twin" name="phone" placeholder="PHONE">
<select name="focus" id="contact-focus">
<option value="" disabled selected>Interested In...</option>
<option value="v0">Opt1 Inquiry</option>
<option value="v1">Opt2</option>
<option value="v2">Opt3</option>
</select>
<textarea id="message" name="message" type="text" placeholder="Details, Availability, Questions, etc"></textarea>
<input id="submit" type="submit" value="GO!">
</form>
PHP:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email1 = "myemail@gmail.com";
$email2 = "myotheremail@gmail.com";
$email_subject = "PT Website Inquiry";
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['message'])) {
died('We apologize, but something weird happened. Please try again.');
}
$name = $_POST['name']; //
$email_from = $_POST['email']; //
$phone = $_POST['phone']; //
$focus = $_POST['focus'];
$message = $_POST['message']; //
$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 First 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 = "Someone submitted our website's contact form, here are the details:
";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."
";
$email_message .= "Email: ".clean_string($email_from)."
";
$email_message .= "Phone: ".clean_string($phone)."
";
$email_message .= "They expressed interest in: ".clean_string($focus)."
";
$email_message .= "Message:
".clean_string($message)."
";
$email_message .= "****************
DO NOT REPLY
****************";
// create email headers
$headers = 'From: '.$email_from."
".
'Reply-To: '.$email_from."
" .
'X-Mailer: PHP/' . phpversion();
mail($email1, $email_subject, $email_message, $headers);
mail($email2, $email_subject, $email_message, $headers);
// header('Location: http://allcalrecycling.com');
echo "<script>
alert('Thank you! We will reach out shortly.');
window.location.href='index.html';
</script>";
?>
<?php
}
?>