jcoones Posted May 25, 2006 Share Posted May 25, 2006 [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]The Explanation[!--colorc--][/span][!--/colorc--]:I have looked at a few tutorials on mailing form input to a particular email address but they all use examples of a form with a set number of fields and use the "name=" to get the field data.For example a simple form such as:<form action="process.php" meathod="POST">Enter your First name: <input type="text" name="first">Enter your Last name: <input type="text" name="last"><input type="submit" value="Submit"></form>Then using php to get the form input they would use something like:<?php$firsname = $_POST[first];$lastname = $_POST[last];?>[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]The Question:[!--colorc--][/span][!--/colorc--]It seems to me that the above method of getting the form input is fine if you know how many fields are in the form and what the "name=" values are. But how would you create a mailer that could be used for a number of different forms with a different number of fields in each form? If using different forms with the same mailer, how would you code it so that the mailer would be able to get all of the form input without knowing how many fields there are or what the "name=" values are?I'm not sure if I am being clear with the question but I think you should be able to get the idea.Would you use an array in the form and then in the mailer use $_POST['array[]'] and a foreach to get all of the input or how would it be done?I know that there are mailers out there that can be used with almost ANY form and mail the input out but I don't know how it does it?Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/ Share on other sites More sharing options...
nogray Posted May 25, 2006 Share Posted May 25, 2006 If you use a form like this[code]<form action="process.php" meathod="POST">Enter your First name: <input type="text" name="first">Enter your Last name: <input type="text" name="last"><input type="submit" value="Submit"></form>[/code]in the PHP backend, run through the post variable to output create the message like this[code]foreach($_POST as $key=>$value){ $message .= "$key: $value \n";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39011 Share on other sites More sharing options...
jcoones Posted May 25, 2006 Author Share Posted May 25, 2006 Thank you very much. I'll give that a shot.Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39019 Share on other sites More sharing options...
jcoones Posted May 26, 2006 Author Share Posted May 26, 2006 I tried the code and it works great! The only problem now is that for some reason the new line, " \n", is not being recognized. the $message is all coming out on one line as opposed to placing each input on a separate line, one below the other. Makes for better readability. Any idea as to what might cause this?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39206 Share on other sites More sharing options...
nogray Posted May 26, 2006 Share Posted May 26, 2006 If you are sending the message as HTML replace the \n by <br />, if not, try to use \r\n instead.If that doesn't work, then I am clueless! Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39308 Share on other sites More sharing options...
jcoones Posted May 27, 2006 Author Share Posted May 27, 2006 Thanks a bunch. I'll try that.I had to use the <br />. The "\r\n" didn't do it.Thanks again, very much. Quote Link to comment https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39355 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.