Jump to content


Photo

Form Mailer help


  • Please log in to reply
5 replies to this topic

#1 jcoones

jcoones
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 25 May 2006 - 08:35 PM

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

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 25 May 2006 - 09:19 PM

If you use a form like this
<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>

in the PHP backend, run through the post variable to output create the message like this
foreach($_POST as $key=>$value){
     $message .= "$key: $value \n";
}

NoGray.com


#3 jcoones

jcoones
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 25 May 2006 - 09:32 PM

Thank you very much. I'll give that a shot.

Thanks again.


#4 jcoones

jcoones
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 26 May 2006 - 03:08 PM

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


#5 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 26 May 2006 - 10:03 PM

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!

NoGray.com


#6 jcoones

jcoones
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 27 May 2006 - 02:22 AM

Thanks a bunch. I'll try that.



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

Thanks again, very much.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users