What PHP function is currently being used to send the user input via email, and how can it be modified to store the data in a database instead?
The PHP function currently being used to send user input via email is `mail()`. To modify it to store the data in a database instead, you can create a database connection, insert the user input into the database table, and then send a confirmation email to the user. This way, the user input will be saved in the database for future reference.
// Database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert user input into database
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$sql = "INSERT INTO user_inputs (name, email, message) VALUES ('$name', '$email', '$message')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Send confirmation email to the user
$to = $email;
$subject = "Thank you for your submission";
$body = "We have received your input. Thank you for reaching out.";
mail($to, $subject, $body);
// Close database connection
$conn->close();