Sending all Form Input
Moderator: General Moderators
Sending all Form Input
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
Thanks
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");
?>-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
here is a basic mail script
there is also a few other things for sending an email in HTML format but this is a simple text email
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);
?>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.
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
$_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
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
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
try something like:
Code: Select all
foreach($_POST as $key => $value){
$message .= $key." : ".$value."/n";
}*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);
?>
?>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);
?>