Hi everyone!
I'm almost ready to launch my website promoting my computer training business. Unfortunately, I'm having trouble with my contact form. As far as I can tell, it should be working. I've had others examine it as well, and say it should work. I know PHPMailer is working on my server, I did a test. Following is the code for the html and php:
HTML
<form id="form" method="POST" action="bat/contact.php">
<div class="success_wrapper">
<div class="success">Contact form submitted!<br>
<strong>We will be in touch soon.</strong> </div></div>
<fieldset>
<label class="name">
<input type="text" value="Name:">
<br class="clear">
<span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span> </label>
<label class="email">
<input type="text" value="E-mail:">
<br class="clear">
<span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
<label class="phone">
<input type="tel" value="Phone:">
<br class="clear">
<span class="error error-empty">*This is not a valid phone number.</span><span class="empty error-empty">*This field is required.</span> </label>
<label class="message">
<textarea>Message:</textarea>
<br class="clear">
<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
<div class="clear"></div>
<div class="btns"><a data-type="reset" class="btn">clear</a><a data-type="submit" class="btn">submit</a>
<div class="clear"></div>
</div></fieldset></form>
PHP:
<?php
if(isset($_POST['submit'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
//$email_to = "crivest@solsticetraining.ca";
$email_to = "crivest@solsticetraining.ca";
// EDIT THE 2 LINES BELOW AS REQUIRED
//$sender = "crivest@solsticetraining.ca";
$sender = "crivest@solsticetraining.ca";
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$phone = $_POST['phone']; // required
$message = $_POST['message']; // required
$email_message = "Form details below.\n\n";
$email_subject = "Contact details - $name";
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 .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From:'.$sender."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent= @mail($email_to, $email_subject, $email_message, $headers);
if($sent){
echo "<script>alert('Contact form submitted! We will be in touch soon.')
location.replace('index4.html')
</script>";
}
else {
echo "<script>alert('Sorry! Something went wrong')
location.replace('index-4.html')
</script>";
}
}
?>
Maybe I'm missing something obvious. First, I'd like to see the form actually work. Then I can worry about security. The form can be seen at www.solsticetraining.ca/index-4.html
Thanks for all the help!