Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/10460-form-mailer-help/
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]
Link to comment
https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39011
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
Link to comment
https://forums.phpfreaks.com/topic/10460-form-mailer-help/#findComment-39206
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.