PDA

View Full Version : After a form submission have email auto sent



immersion08
09-19-2005, 03:19 AM
I'm not sure if this is the right section for this question.
I have a simple contact form on my site. I want to have a pre-made email be auto sent out to the user right after they submit the form. Maybe this could be done through php, or through the form submission? If anyone knows of a way to do this is php, html or anything please reply.

Thank you! :D

dtroi50
09-24-2005, 03:13 PM
I'm not sure if this is the right section for this question.
I have a simple contact form on my site. I want to have a pre-made email be auto sent out to the user right after they submit the form. Maybe this could be done through php, or through the form submission? If anyone knows of a way to do this is php, html or anything please reply.

Thank you! :D


<?php
$to = $_POST['email'];
$from = ""; //the email address you want it from (the address does not have to exist to work)
$headers = "From: $from";
$subject = "Autoreply";
$message = "Replace this with your custom email message";
$mailsent = mail($to, $subject, $message, $headers);

if ($mailsent) {
echo "<p>Yay! The following data has been sent:<br /><br />";
echo "<strong>By: </strong> " . $from . "<br />";
echo "<strong>About:</strong> " . $subject . "<br />";
echo "<strong>Comments:</strong>
" . $message . "<br />";
echo "</p>";
}
else {
echo "There was an error sending this data. Please retry";
}
?>

That will send a mail to the user on submit. Use this form to send it:


<form action="script.php" method="post">
<label for="email">Your email</label><br />
<input name="email" id="email" />
<input type="submit" value="send me a mail" />
</form>