After submitting form how to get own mail information
When you submit a form, you can use various methods to retrieve the form data, including the user's email information. Here are a few approaches:
1. Using PHP and HTML forms
In PHP, you can use the $_POST
or $_REQUEST
superglobals to access the form data. Here's an example:
<?php
// Get the form data
$email = $_POST['email'];
// Send an email using the user's email
$to = $email;
$subject = 'Form submission';
$message = 'Hello, thank you for submitting the form!';
mail($to, $subject, $message);
?>
In your HTML form, make sure to include the name
attribute for the email input field:
<form action="submit.php" method="post">
<input type="email" name="email" placeholder="Your email">
<input type="submit" value="Submit">
</form>
2. Using JavaScript and AJAX
You can use JavaScript and AJAX to send the form data to a server-side script and retrieve the user's email information. Here's an example using jQuery:
$(document).ready(function() {
$('#myForm').submit(function(event) {
event.preventDefault();
var formData = $(this).serialize();
$.ajax({
type: 'POST',
url: 'submit.php',
data: formData,
success: function(data) {
// Do something with the user's email
console.log(data.email);
}
});
});
});
In your HTML form, add a name
attribute to the email input field:
<form id="myForm">
<input type="email" name="email" placeholder="Your email">
<input type="submit" value="Submit">
</form>
3. Using a server-side language like Node.js and Express.js
If you're using a Node.js and Express.js framework, you can use the req.body
object to access the form data. Here's an example:
app.post('/submit', function(req, res) {
var email = req.body.email;
// Send an email using the user's email
var to = email;
var subject = 'Form submission';
var message = 'Hello, thank you for submitting the form!';
transporter.sendMail({ from: '[email protected]', to: to, subject: subject, text: message }, function(error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
});
In your HTML form, add a name
attribute to the email input field:
<form action="/submit" method="post">
<input type="email" name="email" placeholder="Your email">
<input type="submit" value="Submit">
</form>
Remember to replace submit.php
with the actual name of your server-side script, and [email protected]
with your actual email address.