School of Computing  |  Napier  |  Cisco  |  SFC  |  NOS  |  Code |  Old page

PHP - Emailing details

The following shows a simple example of how PHP can email the details from a form, to a remote email address:

Emailing a form

Send an email to me. Write your message here:
<form action="formmail.php" method="POST">
<input type="hidden" name="recipient" value="w.buchanan@napier.ac.uk">
<input type="hidden" name="subject" value="Reply Form">
<input type="text" name="input">
<input type="submit" value="Send">
</Form>
The contents of formmail.php3 are:
<?php
$fmt_Response=implode("", file("response.htt"));
$fmt_Mail=implode("", file("mail.htt"));
while(list($Key, $Val)= each($HTTP_POST_VARS)) {
$fmt_Response=str_replace("{$Key}", $Val, $fmt_Response);
$fmt_Mail=str_replace("{$Key}", $Val, $fmt_Mail);
}
mail($HTTP_POST_VARS["recipient"], $HTTP_POST_VARS["subject"], $fmt_Mail);
echo $fmt_Response;
?>

The response.htt file just contains the page which appears after the user has successfully send the email, such as:
<p>Yippee!!! You've just sent an email to me.
<p><a href="Javascript:history.back()">Back</a>


Executed code

Send an email to me. Write your message here:

 

 

 

School of Computing  |  Napier  |  Cisco  |  SFC  |  NOS  |  Code |  Old page

Page maintained by bill