Page 1 of 1
Sending all Form Input
Posted: Mon Sep 09, 2002 11:51 am
by Zoram
I'm trying to figure out how i can compile all the input from a form and send it using the mail function. I've got a form setup to send to the script but i'm not sure how to setup the script to mail everything submitted.
Thanks
Posted: Mon Sep 09, 2002 12:16 pm
by Takuma
Code: Select all
<?php
$username = $_POSTї"username"];
$email = $_POSTї"email"];
$message =
"Username: $username
E-mail address: $email";
mail("TO ADDRESS","SUBJECT","MESSAGE","From: FROM ADDRESS");
?>
If you have two text field in the form
Posted: Mon Sep 09, 2002 12:16 pm
by JPlush76
here is a basic mail script
Code: Select all
<?php
// set the address the mailform will be sent to
$toaddress = "plush@yoursite.com";
// type in the subject of the email
$subject = "FREE CD REQUEST";
// here is where you have your fields you collected from your form
$mailcontent = "Name: ".$name."\n"
."Email: ".$email."\n"
."Add1: ".$add1."\n"
."Add2: ".$add2."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Zip: ".$zip."\n"
// set the from address which is what the email will say "SENT FROM"
$fromaddress = "info@yoursite.com";
// finally send off the email in the proper form
mail($toaddress, $subject, $mailcontent, $fromaddress);
?>
there is also a few other things for sending an email in HTML format but this is a simple text email
Posted: Mon Sep 09, 2002 12:40 pm
by Zoram
What about when i can't predict how many form elements are being passed in? I am making a contest page for my site and to be entered into the contest the user checks the checkbox by the contest and then fill out the submit info. The only constant thing is all of it is the user info. Everything else id dynamic.
Posted: Mon Sep 09, 2002 12:44 pm
by kcomer
You could always loop through the $_POST array. That will give you all the values from the form, even hidden ones. It may work for what you are doing.
foreach($_POST as $key=>$value) {
print "$key: $value";
}
Just mix it in with your mail script.
Keith
Posted: Mon Sep 09, 2002 12:46 pm
by Zoram
How would the $key and $value variable catch all the values?
kcomer wrote:You could always loop through the $_POST array. That will give you all the values from the form, even hidden ones. It may work for what you are doing.
foreach($_POST as $key=>$value) {
print "$key: $value";
}
Just mix it in with your mail script.
Keith
Posted: Mon Sep 09, 2002 12:55 pm
by kcomer
$_POST is an array that holds every single key/variable pair that was submited by the previouse form. If you print all of those then you have all the forms values. Also, depending on your version you may have to use $_HTTP_POST_VARS. As always, read the php manual, its better than any book or message board.
run this code on the page that processes the form, it will show you what $_POST is holding. Or any other array for that matter.
<?
print "<pre>";
print_r($_POST);
print "</pre>";
Keith
Posted: Mon Sep 09, 2002 2:59 pm
by hob_goblin
try something like:
Code: Select all
foreach($_POST as $key => $value){
$message .= $key." : ".$value."/n";
}
Posted: Mon Sep 09, 2002 5:28 pm
by Coco
*copy from jplush*
Code: Select all
<?php
// set the address the mailform will be sent to
$toaddress = "plush@yoursite.com";
// type in the subject of the email
$subject = "FREE CD REQUEST";
// here is where you have your fields you collected from your form
$mailcontent = "Name: ".$name."\n"
if ($email!='')
$mailcontent = $mailcontent ."Email: ".$email."\n";
if ($nextvalue!='')
//ETC;
// set the from address which is what the email will say "SENT FROM"
$fromaddress = "info@yoursite.com";
// finally send off the email in the proper form
mail($toaddress, $subject, $mailcontent, $fromaddress);
?>
?>
Posted: Tue Sep 10, 2002 12:56 am
by Takuma
Put it all together like this:-
Code: Select all
<?php
$toaddress = "mail@mail.com"; //E-mail address that you are sending
$subject = "Subject of e-mail";
$fromaddress = mail2@mail.com"; //The e-mail address of the sender
foreach($_POST as $key => $value){
$message .= $key." : ".$value."\n";
}
mail($toaddress,$subject,$message,$fromaddress);
?>