For beginners in the field of web development, we usually find ourselves starting out with the XAMPP package to develop using PHP/MySQL. There are times that we need to send emails from our web applications using the PHP mail() function.
If you have access to your ISPs SMTP server. you may configure it in your PHP configuration file. You may use phpinfo() to help you find your configuration file. (in my xampp installation it is at F:\xampp\apache\bin\php.ini)
In your PHP.ini find the ff: lines and modify them using your ISPs SMTP server.
In this example I am using PLDT’s SMTP server. You may surf the web for SMTP servers of other ISPs like the one I found here
SMTP = smtpdsl4.pldtdsl.net
smtp_port = 587
For some cases, your ISP blocks you from using their SMTP servers, for those cases you may still be able to send emails using a gmail account. For this you need to have newer versions of XAMPP since older XAMPP packages have old sendmail files. You may still use an old XAMPP version if you replace the default sendmail folder that came with your package with a new sendmail folder from new XAMPP packages.
In your PHP.ini find the ff: lines and modify them
;SMTP = smtpdsl4.pldtdsl.net
;smtp_port = 587
sendmail_path = “F:\xampp\sendmail\sendmail.exe -t”
mail.add_x_header = Off
In your sendmail.ini (mine is at F:\xampp\sendmail\sendmail.ini)
find the [sendmail] block and add the ff: values.
You will need to input a gmail email address and password so I strongly suggest that you create a dummy account for this purpose.
DO NOT USE YOUR PERSONAL EMAIL ADDRESS
restart apache and then try to send a test email
$headers = “Reply-To: firstname.lastname@example.org\nFrom:email@example.com\nContent-Type: text/html;charset=iso-2022-jp\nX-Mailer: PHP/” . phpversion();
$subject = “test email”
$to = “firstname.lastname@example.org”;
$body = ‘test’;
echo mail($to, $subject ,$body , $headers);