<?php
if($_POST['formsubmitted'] == true){
$mailto = 'youremail@example.com'; //your email address here
$subject = 'eMail From Website'; //change your subject line
$message = 'Message sent from website:'."\r\n"; //header for the eMail
//Notice the \r\n which adds a line break.
//now let's assemble the message:
foreach($_POST as $key => $value){
if(strpos($key,'formvalue')){
//this looks through the posted information to find anything submitted
//that has "formvalue" as part of the name. It returns true if it does.
$message.="$key: $value \r\n"; //appends the value along with the label to the message.
}
}
//now we try to send, and if it works display a message.
$successMessage = 'Thank you for your time.'; //Modify your message
if(mail($mailto, $subject, $message)){
//the mail function returns true if it is successful
echo $successMessage;
}else{
echo 'I\'m sorry, there was a problem submitting your data.';
}
}else{
//this is the form for information. note that all name attributes have
//"formvalue-" as part of them, which will later be used to assemble the message.
echo '
<form action="?" method="post">
What is your name? <input type="text" name="formvalue-name" size="30" />
What is your age? <input type="text" name="formvalue-age" size="30" />
<input type="submit" name="formsubmitted" value="true" />
</form>
';
}
?>