Click to See Complete Forum and Search --> : Form to email!


Nine Years Old
08-26-2005, 09:25 AM
Hi! I have made a form with several fields and I want the contents mailed to me when the form is submitted. I will be adding other fields later. Is there a simple way to do this because everything I have seen is very complicated?

<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset id="fieldset">
<label for="name">Contact name<span class="red">*</span>:</label>
<input class="form_elements" id="name" type="text" name="name" value="" tabindex="1" />
<br />
<label for="email">E-mail address<span class="red">*</span>:</label>
<input class="form_elements" id="email" type="text" name="email" value="" tabindex="1" />
<br />
<label for="subject">Subject<span class="red">*</span>:</label>
<input class="form_elements" id="subject" type="text" name="subject" value="" tabindex="1" />
<br />
<label for="comments">Comments<span class="red">*</span>:</label>
<textarea class="form_elements" id="comments" name="comments" cols="19" rows="5" tabindex="1"></textarea>
<br /><br />
<label for="submit"><span class="red">*</span> Compulsory fields.</label>
<input id="submit" type="submit" name="submit" value="Send" tabindex="1" />
</fieldset>
</form>

bokeh
08-26-2005, 09:43 AM
If you want simple here it is:<?php
if(isset($_POST['submit'])){
$message = '';
foreach($_POST as $k => $v){
$message .= "$k: $v\n\n";
}
mail('recipient@domain.com', 'Subject', $message);
}
?>That will work however many fields you add.

marcato15
08-26-2005, 04:20 PM
This will send all variables including the submit variable


<?php
if(isset($_POST['submit'])){
$message = '';
foreach($_POST as $k => $v){
$message .= "$k: $v\n\n";
}
mail('recipient@domain.com', 'Subject', $message);
}
?>


This will send all variables besides the submit variable, not that its that big of a deal though

<?php
if(isset($_POST['submit'])){
$message = '';
foreach($_POST as $k => $v){
if($k!='submit')
$message .= "$k: $v\n\n";
}
}
mail('recipient@domain.com', 'Subject', $message);
}
?>

bokeh
08-26-2005, 04:26 PM
This will send all variables including the submit variableI knew that but he said simple! Have you ever seen a simpler mailer script?

Sheldon
08-26-2005, 04:43 PM
I knew that but he said simple! Have you ever seen a simpler mailer script?

No i havnt that is a simple mail script if ever i saw one!