The best way to add interactivity to your site with PHP is by adding a comment form.The only difference this time is that we'll be using the mail() function, which is what sends the user's input to your email address.
First, we create the HTML form:
<form action="formmail.php" method="post"> Name: <input type="text" name="name"><br> Email: <input type="text" name="email"><br> Comments: <textarea name="comments"></textarea><br> <input type="submit"> </form>Then we create the "formmail.php" file:
<?php
// your email address
$youremail = "kali@xentrik.net";
// field validation
if ($email=="" || $comments=="" || $name=="")
{
print ("All fields are required! Please go back and try again.");
}
else {
// send email
$headers = "From: \"$name\" <$email>\n";
$subject = "Feedback Form";
$message = "$comments";
mail ("$youremail", "$subject", $message, $headers);
print ("Thank you $name, your email has been sent.");
}
?>
Now, what does it mean?// email validation
if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
print ("Your email address does not appear to be valid. Please go back and try again.");
exit;
}
This says "If $email is not in a name@domain.com format, perform the print() function stated."<?php
// your email address
$youremail = "kali@xentrik.net";
// field validation
if ($email=="" || $comments=="" || $name=="")
{
print ("All fields are required! Please go back and try again.");
}
else {
// email validation
if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
print ("Your email address does not appear to be valid. Please go back and try again.");
exit;
}
// send email
$headers = "From: \"$name\" <$email>\n";
$subject = "Feedback Form";
$message = "$comments";
mail ("$youremail", "$subject", $message, $headers);
print ("Thank you $name, your email has been sent.");
}
?>
Can't find what you're looking for? Try searching for it:
© 2000-2008 Xentrik.Net