Thursday, February 7, 2008

Using the mail() function in php

I've been using this function quite a lot. I just want to share how to use this function which is very easy.

The mail() function in php is used to send email.

Examples :

$to = "name@example.com";
$subject = "Test Subject"; //be careful to have this as one line or it will not be sent properly
$message = "This is the message";

// sends am email to $to email address with subject $subject and message $message
mail($to, $subject, $message);

//example header
$headers = "From : admin@example.com
Reply-To : admin@example.com";

//this time we added the optional parameter headers
mail($to, $subject, $message, $headers);


That's basically it. Now you know how to send emails in php.