sloppycode.net
Form to email example
A basic form to email snippet.
Home
›
Code snippets
›
PHP
›
Form to email example
This is a basic form to emailer in PHP. It requires a html form with a 4 text boxes named: 'name','phone','email','message'.
Like all PHP on sloppycode.net this example was made in PHP 3.x or 4, so unfortunately isn't guaranteed to be error free anymore.
<? if (!empty($HTTP_POST_VARS)) { $now = date("D dS M h:m:s"); // Set these variables according to your details $toAddress = "youraddress@yourdomain.com"; $subject = "Contact Form Information"; $website = "http://www.yourdomain.com"; // Form information. // Change HTTP_POST_VARS to HTTP_GET_VARS if the form uses GET as its method $formEmail = $HTTP_POST_VARS['email']; $formName = $HTTP_POST_VARS['name']; $formPhone = $HTTP_POST_VARS['phone']; $formMessage = $HTTP_POST_VARS['message']; // Email message $message = "Here is information submitted on the contact page at\n"; $message .= $website." on ".$now."\n"; $message .= "Name : ".$fromName."\n"; $message .= "Phone :".$formPhone."\n"; $message .= "Email: ".$formEmail."\n"; $message .= "Comments:\n"; $message .= $formMessage."\n"; $bMailSent = mail($toAddress,$subject,$message); if (!$bMailSent){ "Unable to send email"; } else{ // Customise this for the 'thank you' page after the form has been submitted echo "Your details have been sent"; } } ?>
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search
› Sitemap
Buy on Amazon
Buy on Amazon
Buy on Amazon
Buy on Amazon