PDA

View Full Version : PHP mail form - modification



nitelava
March 14th, 2007, 11:43 PM
Love the form tutorial -- Thanx!

Q: how can i send a confirmation email with a generic text + form output to the user who is sending the form? Here is the code:

<?php
if(isset($_POST['submit'])) {

$to = "msn@msn.com";
$subject = "Subject!";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$dropdown = $_POST['drop_down'];
$city_field = $_POST['city'];
$terms_field = $_POST['terms'];

foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}

} else {
$body = "Full Name: $name_field\n $check_msg E-Mail: $email_field\n $check_msg Daytime Phone: $phone_field\n $check_msg State: $dropdown\n $check_msg City: $city_field\n $check_msg Terms & Conditions: $terms_field\n";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {
echo "blarg!";
}
?>

Thanx!

DHDesign
March 15th, 2007, 01:05 PM
well, there a few things that are wrong with what you have right now...

first off, you have two "else" statements, but just one "if"...what is the second "else" closing?

Also, include a $from field in the mail function.

Anyway, here is a good site to help you out: http://php.about.com/od/phpapplications/ss/form_mail.htm