This part of the code goes on your web page. Place it inside the <body> tag where you would like it to appear.
<!-- Contact form provided by http://www.top-site-list.com -->
<form class="contactForm" action="submit-contact-form.php" method="post">
<label>Your name<br/>
<input type="text" name="name" placeholder="Please enter your name." required="required" /></label>
<label>Your email address<br/>
<input type="email" name="email" placeholder="Please enter your email." required="required" /></label>
<label>Subject<br/>
<input type="text" name="subject" placeholder="Summary of message" required="required" /></label>
<label>Message<br/>
<textarea required="required" name="message" placeholder="Write your message here." rows="5" style="width:500px;"></textarea></label>
<input type="submit" value="Send Message" />
</form>
This is the PHP code that runs on your server. Copy this code to a new file and name it submit-contact-form.php
and save it in the same location as the page with the form from the first step. Make sure you entered your details in the boxes at the top of this page so the right code has been generated here.
<?php
$sendToEmail = "you@example.com";
$redirectToUrl = "http://www.google.com";
if (!empty($_POST)) {
if (!($name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH))) {
die("Please enter your name");
}
if (!($email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL))) {
die("Please enter a valid email address");
}
if (!($subject = filter_input(INPUT_POST, "subject", FILTER_SANITIZE_STRING))) {
die("Please enter a subject");
}
if (!($message = filter_input(INPUT_POST, "message", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH))) {
die("Please enter a message");
}
if (mail($sendToEmail, $subject, $message, "From: <{$email}> {$name}")) {
header("Location: ". $redirectToUrl);
} else {
die("Message failed to send.");
}
}