Fearpig Posted October 24, 2006 Share Posted October 24, 2006 Hi guys,I've got a problem that must be dead easy to solve I've just been looking at it for too long! I'm generating an e-mail based on a php form. I'm trying to include all the fields into the body of the e-mail. So far I have:[code]<?php$email = 'someone@domain.co.uk';$subject = 'literature request';$message = $HTTP_POST_VARS['Name'];if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>";} elseif ($subject == "") { echo "<h4>No subject</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>";}elseif (mail($email,$subject,$message)) { echo "<h4>Thank you for sending email</h4>";} else { echo "<h4>Can't send email to $email</h4>";}?>[/code]So far it validates the e-mail address and subject but only passes one one of te fields ($message = $HTTP_POST_VARS['Name'];). How would I change this single field to:[code]foreach ($_POST as $part => $qty){ echo "$part - $qty<br>";}[/code]This code just grabs all of the variables passed on by the page before. I need to do it this way as the fields are generated by a database and I won't know field names untill the page is generated. I'd really appreciate any help from you guys! ;DCheersTom Quote Link to comment Share on other sites More sharing options...
kirk112 Posted October 24, 2006 Share Posted October 24, 2006 You are nearly there, if you place all the information into a variable and the add this to the message value it should work [code]$items = NULL;foreach ($_POST as $part => $qty){ $items .= "$part - $qty<br>";}$message = " ". $HTTP_POST_VARS['Name'] ." ". $items ." ";[/code]Hope it works and this is what you where after Quote Link to comment Share on other sites More sharing options...
Fearpig Posted October 24, 2006 Author Share Posted October 24, 2006 Dimond! ;DLittle bit of tweaking to get it formatted as I wanted but you've solved the problem. Thanks Kirk112. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.