How send mail any form details fill
You want to know how to send an email with form details filled in. Here are a few ways to do it:
Method 1: Using a simple HTML form and PHP
- Create an HTML form with the fields you want to send:
<form action="send_email.php" method="post"> <input type="text" name="name" placeholder="Name"> <input type="email" name="email" placeholder="Email"> <textarea name="message" placeholder="Message"></textarea> <input type="submit" value="Send"> </form>
- Create a PHP file (
send_email.php
) to process the form data and send the email:<?php // Get the form data $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message'];
// Set the email recipient and subject $to = '[email protected]'; $subject = 'Form Submission';
// Create the email message $message = "Name: $name\nEmail: $email\nMessage: $message";
// Send the email using PHP's mail function mail($to, $subject, $message);
// Redirect the user to a thank-you page header('Location: thank-you.php'); exit; ?>
**Method 2: Using a JavaScript library like jQuery and a PHP backend**
1. Create an HTML form with the fields you want to send:
```html
<form id="myForm">
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<textarea name="message" placeholder="Message"></textarea>
<input type="submit" value="Send">
</form>
- Use jQuery to serialize the form data and send it to your PHP backend:
$('#myForm').submit(function(event) { event.preventDefault(); var formData = $(this).serialize(); $.ajax({ type: 'POST', url: 'send_email.php', data: formData, success: function(data) { // Redirect the user to a thank-you page window.location.href = 'thank-you.php'; } }); });
- Create a PHP file (
send_email.php
) to process the form data and send the email:<?php // Get the form data $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message'];
// Set the email recipient and subject $to = '[email protected]'; $subject = 'Form Submission';
// Create the email message $message = "Name: $name\nEmail: $email\nMessage: $message";
// Send the email using PHP's mail function mail($to, $subject, $message);
// Redirect the user to a thank-you page header('Location: thank-you.php'); exit; ?>
**Method 3: Using a JavaScript library like React and a PHP backend**
1. Create an HTML form with the fields you want to send:
```html
<form>
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit">Send</button>
</form>
- Use React to handle the form submission and send the data to your PHP backend:
import React, { useState } from 'react';
function MyForm() { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [message, setMessage] = useState('');
const handleSubmit = (event) => { event.preventDefault(); fetch('/send_email.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, email, message }), }) .then((response) => response.json()) .then((data) => { // Redirect the user to a thank-you page window.location.href = 'thank-you.php'; }); };
return (
); } ``` 3. Create a PHP file (`send_email.php`) to process the form data and send the email: ```php // Set the email recipient and subject $to = 'your_email@example.com'; $subject = 'Form Submission';// Create the email message $message = "Name: $name\nEmail: $email\nMessage: $message";
// Send the email using PHP's mail function mail($to, $subject, $message);
// Redirect the user to a thank-you page header('Location: thank-you.php'); exit; ?>
These are just a few examples of how you can send an email with form details filled in. The specific implementation will depend on your requirements and the technologies you are using.