The easiest way to start developing in PHP is to get XAMPP, the whole package can even be placed in a flash drive.
0. Objective
To get your PHP scripts to send an email out. This guide assumes you have XAMPP or XAMPP Lite. My environment is Windows Vista. (I use XAMPP Lite by the way)
My XAMPP is placed in C:\xampp\, so your configuration may be a little different. The files to be modified are sendmail.ini and php.ini.
1. Modify your sendmail.ini
Your sendmail.ini should be located in C:\xampp\sendmail\sendmail.ini. You only need to be concern with 3 variables here:
- smtp_server
- auth_username
- auth_password
Get them filled in, an example would be as follows:
smtp_server=smtp.mail.com
auth_username=mail@mail.com
auth_password=******
2. Modify your php.ini
XAMPP places the php.ini inside C:\xampp\apache\bin\php.ini. You can open the file and do a search for ‘sendmail_path’. It’s at line 704 for me. You can simply uncomment that line.
sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”
And that’s all. Now for some testing.
3. Let’s test it out
<?php
$from_name = "YourName";
$from_email = "mail@mail.com";
$headers = "From: $from_name <$from_email>";
$body = "Hi, \nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail ";
$to = ‘to@mail.com’;
if (mail($to, $subject, $body, $headers)) {
echo "success!";
} else {
echo "fail…";
}
?>
Execute those codes and you should receive something in your inbox. Here’s what I see in Gmail:
Sources
http://i.justrealized.com/2008/how-to-use-sendmail-in-xampp/
Thx a lot 🙂