This guide explains how to create a form and set it up to collect and send
responses to your email. It covers three methods:
- Using HTML’s
mailto:attribute - Using third-party form processing services
- Using PHP for server-side form handling
Method 1: Using HTML mailto: Attribute
The simplest way to send form data is by using HTML’s mailto: attribute.
Here’s how it works.
Step 1: Create a Simple HTML Form
The following HTML code creates a form with basic fields: Name, Email, and Message.
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Contact Form</title>
</head>
<body>
<h2>Contact Us</h2>
<form action=”mailto:sendmemail@tuplea.com.ng” method=”post” enctype=”text/plain”>
<label for=”name”>Name:</label><br>
<input type=”text” id=”name” name=”name” required><br><br>
<label for=”email”>Email:</label><br>
<input type=”email” id=”email” name=”email” required><br><br>
<label for=”message”>Message:</label><br>
<textarea id=”message” name=”message” rows=”4″ required></textarea><br><br>
<input type=”submit” value=”Send”>
</form>
</body>
</html>
Explanation
Action attribute: The mailto: in the action attribute sends form entries directly to
the specified email (sendmemail@tuplea.com.ng).
Method: The post method submits data securely.
Enctype: Setting enctype=”text/plain” formats data in plain text. For more
secure encryption, use enctype=”multipart/form-data”, especially for file uploads.
Considerations
While using mailto: is simple, it has limitations:
- Users need to be logged into an email client for the form to submit.
- It’s not suitable for large-scale data collection or secure data handling.
Method 2: Using Third-Party Platforms
If you need more security or handle a lot of data but don’t want to set up
server-side processing, you can use third-party form-processing services.
Many platforms offer free and paid options.
Sign Up: Register on a form-handling platform.
Generate an ID: Most platforms will generate a unique ID or URL for you.
Set Up: Integrate your form with the platform by inserting the generated
ID or URL into the action attribute of your form.
Examples of Third-Party Platforms includes Formspree, Google Forms,
Getform, FormKeep, Netlify Forms and so on.
Here is how Formspree setup look like;
<form action=”https://formspree.io/f/{form_id}” method=”post”>
<label for=”email”>Your Email</label>
<input name=”Email” id=”email” type=”email”>
<button type=”submit”>Submit</button>
</form>
Google Forms: Google Forms generates an embed code:
<iframe src=”https://docs.google.com/forms/d/e/YOUR_FORM_ID/viewform?embedded=true” width=”640″ height=”800″ frameborder=”0″ marginheight=”0″ marginwidth=”0″>Loading…</iframe>
Each platform offers various features; choose one that matches your form’s complexity and budget.
Method 3: Using PHP to Handle Form Data
PHP allows you to handle form submissions and send them directly to your
email server-side, bypassing the user’s email client.
Step 1: Set Up the HTML Form
Set the form action to your PHP script (e.g., submit_form.php):
<form action=”submit_form.php” method=”post”>
<input type=”text” name=”name” placeholder=”Name” required>
<input type=”email” name=”email” placeholder=”Email” required>
<textarea name=”message” placeholder=”Message” required></textarea>
<button type=”submit”>Send</button>
</form>
Step 2: Create submit_form.php
Add the following PHP code in submit_form.php:
<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$name = $_POST[‘name’];
$email = $_POST[’email’];
$message = $_POST[‘message’];
$to = “sendmemail@tuplea.com.ng”; // Replace with your email address
$subject = “New Contact Form Submission”;
$body = “Name: $name\nEmail: $email\nMessage:\n$message”;
$headers = “From: $email”;
if (mail($to, $subject, $body, $headers)) {
echo “Thank you for contacting us!”;
} else {
echo “Error: Message could not be sent.”;
}
}
?>
Additional Note
If you’re testing this locally, PHP requires a server to run. XAMPP is a
simple tool to set up a local server:
- Install XAMPP: Download XAMPP.
- Run Apache: Start the Apache server in XAMPP’s Control Panel.
- Move Files: Place files in the htdocs folder (C:/xampp/htdocs).
- Access Project: Visit http://localhost/your-folder/submit_form.php in your browser.
- To send emails on localhost, configure Sendmail.
Setting up Sendmail with XAMPP for Local Email Testing
Step 1: Download and Install Sendmail
- Download Sendmail for Windows from GitHub.
- Extract it to C:\xampp\sendmail.
Step 2: Configure sendmail.ini
In the C:\xampp\sendmail\sendmail.ini file:
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
auth_username=your_email@gmail.com
auth_password=your_password
default_domain=localhost
Step 3: Configure php.ini
In php.ini (found in C:\xampp\php\), update the sendmail path:
sendmail_path = “\”C:\xampp\sendmail\sendmail.exe\” -t”
Step 4: Restart Apache
Restart Apache in the XAMPP Control Panel to apply the configuration.
Step 5: Test Your PHP Mail Code
To verify email sending, create a simple PHP test file (test_mail.php):
<?php
$to = “recipient@example.com”; // Replace with your test email
$subject = “Test Email from Sendmail”;
$message = “This is a test email sent from Sendmail using XAMPP.”;
$headers = “From: your_email@gmail.com”;
if (mail($to, $subject, $message, $headers)) {
echo “Email sent successfully!”;
} else {
echo “Failed to send email.”;
}
?>
Open this file in your browser (http://localhost/test_mail.php) to
check for success.
CONCLUSION
With these methods, you can choose the most suitable way to collect
form responses based on your needs and technical comfort level.
