Forum Moderators: coopster
Just taking this example:
<?php
mail('recipient@some.net', 'Subject', 'Your message here.');
?>
-------------------------------------------------
I have a mixture of form tables that use checkboxes, radio buttons, textareas and the whole nine yards.
How do I format all of the information I have in the form and send it in the mail function?
It seems like I could just take something like...
$message = ...(all the info)
-->but I'm not sure how to transport it all into the variable. Honestly hope that makes sense, very unclear at the moment;)
Thanks-
<input type="radio" name="level"
value="start_novice" />
<input type="radio" name="level" value="start_inter" />
<input type="radio" name="level" value="start_expert" />
for example...I would need the value chosen from the level array- into the $message variable along with similar form info.
Do you mean like this? If I had other arrays like this would it just be a comma separated list or a semi-colon separated list? That's probably thick;)
Also, in the subject of the email response-
$subject = "HelpDesk Inquiry";
--> Can you throw in a date fuction after inquiry so that the time shows up in the email title?
Thanks again!
You do exactly what Lisa showed you but you use the vars that I gave you instead of the generic style ones.
here is a baby template but you will have to do some yourself
$emailto = "address@somewhere.com";
$subject = "HelpDesk Inquiry";
//construct your message here
$message = $_POST["level"];
$message .= $_POST["anotherVar"]
//end message
mail($emailto,$subject,$message);
That should give you a good idea of how to do it. Your message line can be a function, a loop, multiple functions. You can add a date function in there.
php.net is your friend ;)
Your message line can be a function, a loop, multiple functions.
To be precise your message parameter needs to be a string [php.net].
If you use a form like the one in Example 8-3. More complex form variables [php.net] building your message string is as easy as looping through the $form array. Unlike that example I would name the beer select form[beer][] to stay true to the naming scheme. And you should use the auto-global $_POST instead of $HTTP_POST_VARS.
If you have an additional array mapping your keys to nice name you can make processing even easier. In the aforementioned example there are the keys name, email and beer. Suppose you have an array like $nice_names = array(name => 'Customerīs name', email => 'Email address', beer => 'Favorite beer'), then you could do the following:
foreach($form as $key => $value) {
$message .= sprintf("%s: $s\n",
$nice_name[$key],
is_array($value)? implode(', ', $value) : $value);
} Customerīs name: Aaron
Email address: aaron@domain.tld
Favorite beer: warthog, guinness, stuttgarter
Andreas