| NAME: |
|
Contact Form |
| AUTHOR: |
|
punkstar |
| DATE: |
|
27th Nov, 2005 - 01:29:55 PM |
| DESCRIPTION: |
|
Let users send you feedback about your website |
Need some help with that coding?
First you need to start with a form.
| Code | <form action="contact.php" method="post">
Your Name: <input type="text" name="name" /><br />
Your Email Address: <input type="text" name="email" /><br />
Your Message: <textarea name="message"></textarea><br />
<input type="submit" name="submit" value="Contact >>" />
</form> |
If you would like to know how i can use the variables above, then checkout the php section for "How to use forms".
Now, all of that information is going to get sent to the contact.php. There, we need to sort all of the information out first, and then we need to prepare for the mail();
| PHP Code |
<?php
//your email address
$site_email = "contactform@yourwebsite.com";
//the info will come in as $_POST
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if(!empty($name) && !empty($email) && !empty($message))
{
$subject = "Contact Form";
$headers = 'From: '.$email . "rn";
$message = wordwrap($_POST['message'], 65);
//send the email
$mail = mail($site_email, $subject, $message, $headers);
if($mail == true)
{
echo "Mail Successful!";
}
else
{
echo "Mail Failed";
}
}
else
{
echo "Please fill in all the fields";
}
?>
|
Everything above its pretty self explanitory. The function wordwrap(); simply count the letters, and if it gets above 65, then a new line will be started.
The headers that were added to the mail() function, then add the different headers to the email. This can include things like Bcc, Cc and Reply to addresses.
In the above email, it will strap the from header as the email address that was provided on the forum.
Then the conditional checks to see if the mail was successful when the mail was attempted to be sent.
This script is an easy way to set up a quick and easy method to let your users send you some feeback. Copy and Paste =D
|