Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
phpmail (0 Comments)
Admin: Posted Date: April 4, 2010

phpmail is a script written in PHP that allows you to collect feedback from your site visitors and than email the information they enter back to yourself. Allows for easy customization of form fields and layout.


Collect Feedback And Email It To Yourself

This coding example shows how to collect feedback from your site using a form and email the response to yourself.

The first thing we need is the HTML form. Keeping it simple for this example, I ask for only name, email and feedback. Try the form below to see how the user interface works. You won't really send me an email because that would generate too much email for me.

PHP Code That Sends the Email
The PHP code to send email is the PHP function mail(). The basic format for this function is:

mail("to", "subject", "message");
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");

PHP needs to be installed and setup properly to send mail from the server. On a Unix-type setup such as Linux, PHP uses your local sendmail program. Windows machines use SMTP. If you need to, edit your php.ini file and set the appropiate SMTP host to send email.

                        

Here's the code to send the email:

<?
if ($_SERVER['REQUEST_METHOD'] == "POST") {
  
// Just to be safe, I strip out HTML tags   
$realname = strip_tags($realname);   
$email = strip_tags($email);   
$feedback = strip_tags($feedback);   
  
// set the variables   
// replace $me@mysite.com with your email   
$sendto = "$me@mysite.com";   
$subject = "Sending Email Feedback From My Website";   
$message = "$realname, $email\n\n$feedback";   
  
// send the email   
mail($sendto, $subject, $message);   

}   
?>

 

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: