Easiest Way Ever PHP eMail Script

by Hiroshi on June 15, 2008

in Mail

If you thought that sending email using PHP was an alien task then, here is a quick solution. If you are using three fields as name, email and comments then writing an email script using PHP language is like chewing a bubble gum. We take three variables e.g. name, email and comments which user posts and send email.

<?php
// request variables
$name=$_REQUEST["name"];
$email=$_REQUEST["email"];
$comments=$_REQUEST["comments"];
 
if($name)
{
$to = "recipient-email-address@gmail.com";
$subject = "New message from site";
$message = "
Name: $name
Email: $email
Comments: $comments
";
mail($to, $subject, $message);
echo "message sent";
}
?>

Of course there are other bit of details when it comes to a fully functional email script. You can explore mail section of this blog to get a final version of emailing script complete and loaded with validation and other all issues like html-email and multiple recipients case. This example is to show you how easy it is to send mail using PHP.

Related Posts

Previous post:

Next post: