#################################################################
The article was obtained at the following URL: http://www.kfwebs.net/articles/article/5
The article might be distributed further as long as it is provided as it is, with the credits stated.
The Article was written and first published by KF Webs, at http://www.kfwebs.net
#################################################################
A lot of users have requested a simple introduction to using PHP to send an email containing the content of a form. A simple multi-usable approach is therefore presented as following:
Added: 2004-05-25 22:04:15 - Modified: 2004-05-25 20:08:42 - Level: Beginner
As the processing-script uses $_POST it is important to specify a method in the form tag
<form action="/myfile.php" method="post">
The actual .php file will have content as following
<?
$email_adresse = "user@host";
$subject = "This is the subject";
$body = "";
foreach($_POST as $a => $b)
{
$body .= "$a: $b\n";
}
if(mail($email_adresse, $subject, $body)){echo "Mail sent successfully";} else {echo "An error occured";}
?>
This initiate a foreach [ http://www.php.net/foreach ] loop that will loop through the $_POST array and append the data to the $body variable. Therefore this script can be used for many purposes, as you can use several forms and the same script. Happy coding