Hi folks.
I’m trying to use PHP to send me an email when someone fills out a form.
I’m ok with HTML and CSS but PHP is an alien language to me.
What I’ve tried so far (With others helping me) is below. Unfortunately it doesn’t work.
When I fill out the form and hit submit I get the error page. “OOPS”
My html, which works fine, I think, is:
<div class="email">
<form action="/EmailForm/action_page.php">
<label for="fname">First Name</label>
<input type="text" id="name" name="name" placeholder="Your first name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="emailadd">Email Address</label>
<input type="text" id="emailadd" name="emailadd" placeholder="Your email address..">
<label for="phone">Telephone</label>
<input type="text" id="phone" name="phone" placeholder="Your telephone number..">
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
My PHP, which I’ve borrowed and tweeked, is:
<?php
$siteemailtosend="[[email protected]](mailto:[email protected])";
$siteemailtoreceive="[[email protected]](mailto:[email protected])";
if(empty($_POST['fname']) ||
empty($_POST['lname']) ||
empty($_POST['emailadd']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "Opps,!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";
$email_body = "You have received a new message from your website contact form.\n\r\n";
$email_body = $email_body."Here are the details:\n\r\n";
$email_body = $email_body."Name: $fname\n\r\n";
$email_body = $email_body."Last Name: $lname\n\r\n";
$email_body = $email_body."Email: $emailadd\n\r\n";
$email_body = $email_body."Phone: $phone\n\r\n";
$email_body = $email_body."Message: $message\n\n\r\n";
$headers = "From: $siteemailtosend\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
if ((mail($to,$subject,$message,$headers))&&(mail($autoTo, "Thank You from ", $autoreply, 'From: [[email protected]](mailto:[email protected])'))) {
header("Location: ".$goto_after_mail);
$success = "Your message has been sent. We shall reply as soon as we can";
}
?>
Please remember, my PHP knowledge can be written on a pin head.