Jump to content

Archived

This topic is now archived and is closed to further replies.

jcoones

Form Mailer help

Recommended Posts

[!--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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Thanks a bunch. I'll try that.



I had to use the <br />. The "\r\n" didn't do it.

Thanks again, very much.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.