When a user has finished filling out an HTML form and has decided to email the data from the form, I want to send an email using PHP. I want to carry it out using the same script that shows the form-containing web page.
I found this code, but the mail does not send.
<?php
if (isset($_POST['submit'])) {
$to = $_POST['email'];
$subject = $_POST['name'];
$message = getRequestURI();
$from = "zenphoto@example.com";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
echo "Mail Sent.";
}
else {
echo "failed";
}
}
?>
What is the code to send an email in PHP?