Page 1 of 1

a thank you email sent to them once they have filled my form

Posted: Fri Sep 16, 2005 6:11 am
by dazzclub
Hi peolpe, i have a form for users to fill in and once it has been submitted to me., the user will automaticly be sent an e-mail to them from me telling them thanks.

is this possible?

here is my code if it helps

Code: Select all

<?php 
if(isset($_POST['submit'])) { 
$to = "myemail@me.co.uk"; 
$subject = "Form Tutorial"; 
$name_field = $_POST['name']; 
$email_field = $_POST['email']; 
$message = $_POST['message']; 
$menu = $_POST['select']; 
 foreach($_POST['check'] as $value) { 
$check_msg .= "Checked: $value\n"; 
}    



 "<select name=\"select\">"; 
    "<option value=\"prod 1\">prod 1</option>"; 
    "<option value=\"prod 2\">prod 2</option>"; 
    "<option value=\"Alt 3\">Alternative 3</option>"; 
    "<option value=\"Alt 4\">Alternative 4</option>"; 
    "<option value=\"Alt 5\">Alternative 5</option>"; 
    "</select>"; 

  
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message $check_msg $menu"; 
  
echo "Data has been submitted to $to!"; 
mail($to, $subject, $body); 
} else { 
echo "blarg!"; 
} 
?>

Posted: Fri Sep 16, 2005 6:49 am
by shiznatix
of course! you are already sending a e-mail to you, well then if you have their e-mail address just use mail() again and put in their email address as the e-mail address it is being sent to and you will be solid, just put in your own custom message like thanks mate or whatnot

conformation of code

Posted: Fri Sep 16, 2005 8:24 am
by dazzclub
hi, thanks for your help, so wot u told would work like this, if i understood it.

the user will complete my form, then send it to me but at the same time, they will recieve an e-mail from me in their post box saying thank you.

is that correct?

cheers

Posted: Fri Sep 16, 2005 9:30 am
by shiznatix

Code: Select all

<?php
if(isset($_POST['submit'])) {
$to = "myemail@me.co.uk";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$menu = $_POST['select'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}    



"<select name=\"select\">";
    "<option value=\"prod 1\">prod 1</option>";
    "<option value=\"prod 2\">prod 2</option>";
    "<option value=\"Alt 3\">Alternative 3</option>";
    "<option value=\"Alt 4\">Alternative 4</option>";
    "<option value=\"Alt 5\">Alternative 5</option>";
    "</select>";

  
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message $check_msg $menu";
  
echo "Data has been submitted to $to!";
mail($to, $subject, $body);//this sends you the email if i am not mistaken
mail($email_field, 'Thanks Bro', 'Thanks, I got your message and your a champ.');//this will e-mail them saying thanks!
} else {
echo "blarg!";
}
?>

break through at last

Posted: Fri Sep 16, 2005 10:12 am
by dazzclub
lol, i tried that and it didnt work for me. you must have a special touch, cheers, thanks for your help.

one little more question. In the thank you email, can you attach images at all?

thanks for your help

Posted: Fri Sep 16, 2005 10:15 am
by shiznatix
you can send attachments, but i don't think with regular php mail() function unless there are some headers... there is a class, probably on phpclasses website or somthing, thats a bit trickier thing that I have never done. but you can send html emails and put the picture in the e-mail itself without making it a attachment

Posted: Fri Sep 16, 2005 10:31 am
by feyd
mail() can do attachments, it's a bit of a pain.. but it can be done..

I prefer to use phpMailer since it's already done for me then :)

viewtopic.php?t=34242 is the most recent Code Snippet involving attachments using mail()