Steps to making a form on your website where people can email you information (formmail) Print

  • 1

Here are step-by-step instructions to create a simple contact form on your website using FormMail (or similar mail script) so visitors can email you information:

Steps to Create a Contact Form (FormMail) on Your Website

Step 1: Create the HTML Form

Create an HTML file (e.g., contact.html) and add a basic form:

<form action="formmail.php" method="post">
<label>Name:</label><br>
<input type="text" name="name" required><br><br>

<label>Email:</label><br>
<input type="email" name="email" required><br><br>

<label>Message:</label><br>
<textarea name="message" rows="5" required></textarea><br><br>

<input type="submit" value="Send Message">
</form>

Step 2: Create the PHP Script (formmail.php)

Here’s a simple example of a script that sends the form data to your email:

<?php
$to = "you@example.com"; // Replace with your email
$subject = "New Contact Form Submission";

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();

$body = "Name: $name\nEmail: $email\n\nMessage:\n$message";

if (mail($to, $subject, $body, $headers)) {
echo "Thank you for contacting us.";
} else {
echo "Message delivery failed.";
}
?>

Important: This example is very basic. For security, always validate and sanitize user inputs to prevent abuse (like header injection).

Step 3: Upload Files to Your Web Hosting

  • Log in to your cPanel.
  • Open File Manager.
  • Upload contact.html and formmail.php to your website’s public directory (e.g., public_html).

Step 4: Test the Form

  • Visit your form (e.g., https://yourdomain.com/contact.html) [Replace yourdomain.com with your actual domain]
  • Fill it out and submit.
  • Check your email inbox for the test message.

Optional: Use cPanel’s Built-In Email Configuration

  • Make sure your hosting supports mail() function (most do).
  • If needed, configure email routing in cPanel > Email Routing.
  • You can also configure SMTP authentication for better email deliverability.

Extra Tips

  • Use Google reCAPTCHA to prevent spam.
  • Use HTML5 required fields for basic validation.
  • Consider using FormMail clones like Formspree or Formsubmit if you don’t want to handle backend code.

Was this answer helpful?

« Back