This Post about “How to send mail from localhost in php using wamp/xampp”, sometimes we need to test mail sending function from our development environment.We can send mail from our localhost using some mail configuration by XAMPP/LAMP/WAMP server, First we need to enable php_openssl php extensions from
php.ini file.I am using GMAIL SMTP server to send mail from localhost and sendmail package,It is a mail transport agent which can be found in
php.ini file.The sendmail package is inbuilt in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.
The Configuration Parameters in PHP Mail
- smtp_sever : The SMTP Host server name like ,
- smtp_port : The port number(Ex: 465)
- auth_username : Your SMTP username
- auth_password : Your SMTP password
You can also check other tutorial of php mail,
- How To Send Email From Localhost Using PHP
- Send Mail Using Amazon Cloud Server With PHP SMTP
- How to Send Mail in PHP
Step 1: we need to enable php_openssl php extentions from
php.ini file.For XAMPP,it is located in
C:\XAMPP\php\php.ini.You can download from php_openssl.dll.
Step 2: Find mail function in
php.ini file.You can find code like below.
1 2 3 4 5 6 7 8 9
[mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury ; SMTP = localhost ; smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = postmaster@localhost ;sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
replace with you SMTP configuration parameters like below,
1 2 3 4 5 6 7 8 9
[mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP = smtp.gmail.com smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = firstname.lastname@example.org sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
Step 3: Open sendmail.ini which are located on
"c:\xampp\sendmail\sendmail.ini" and change SMTP configuration parameters.
1 2 3 4 5 6
[mail function] smtp_server=smtp.gmail.com smtp_port=25 email@example.com auth_password=XXXXXXX firstname.lastname@example.org
Step 4: Restart your Apache server.
Step 5: Send mail using php
mail("email@example.com","Success","Send mail from localhost using PHP");
Sometime port 25 is not opened, so you need to change 587 OR 465.
Now you have configured mail from localhost and use it.I hope this php tutorial help to understand working functionality of mail and sending mail from localhost using PHP SMTP.