Dynamic PHP Email Forms without massive amounts of code

Ever had a HUGE form that just emails basic information and just thought to yourself, damn there has to be an easier way to do this! I’ve got a solution that will work, basicly what it does is takes the form loops all the input fields and sends them through email (or proccess them any way you would like) I’ll go over the basics here.

First we need a form Lets start with something simple

Name: Email: Address:

Now to process it, first we will import all variables and send them through a loop


$server = $_SERVER['HTTP_HOST'];      

foreach($_POST as $key => $data) { 
  if($key != 'required') { 
      if($data !='') { 
          $message .= ''.$key.': '.$data.''; 


Now you can display your information if you wish or go further to send it with an email, im using a email class i built which you can download here.

echo '


Your forum Has been sucessfully sent with the following information

'.$message.' '; $m = new Mail(); // create the mail $m->From( "email@server.com" ); $m->To( "email@server.com" ); $m->Subject( 'New forum submission from '.$server.' Contact Page' ); $m->Body( $message); $m->Priority(4); $m->Send(); // send the mail

This method is very easy for sending simple forms where serverside validation is not needed. Check it out play with it and post if you have any questions ill be happy to help!