Php

How To Send Email From Localhost Using PHP

In this post about “How to send mail from localhost in php using wamp/xampp”, sometimes we need to test the 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.

I have added one more article: Send Email From Using Gmail API and PHP.

Video Tutorial:

If you are more comfortable in watching a video that explains about How To Send Mail From Localhost Using XAMPP, then you should watch this video tutorial.

The Configuration Parameters in PHP Mail

  • smtp_sever: The SMTP Host server name like, smtp.gmail.com
  • smtp_port: The port number(Ex: 465)
  • auth_username: Your SMTP username
  • auth_password: Your SMTP password

You can also check other tutorials of php mail,

Step 1: we need to enable php_openssl php extensions 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 the mail function in php.ini file. You can find the code like below.

Related Post
[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 your SMTP configuration parameters like the below,

[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 = phpflow@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"

Step 3: Open sendmail.ini which is located on "c:\xampp\sendmail\sendmail.ini" and change SMTP configuration parameters.

[mail function]
smtp_server=smtp.gmail.com
smtp_port=25
auth_username=phpflow@gmail.com
auth_password=XXXXXXX
force_sender=phpflow@gmail.com

Step 4: Restart your Apache server.

Step 5: Send mail using php mail() function.

mail("parvez1487@gmail.com","Success","Send mail from localhost using PHP");

Sometimes port 25 is not open, so you need to change to 587 OR 465.

Now you have configured mail from localhost and use it.I hope this php tutorial helps to understand the working functionality of mail and sending mail from localhost using PHP SMTP.

View Comments

Recent Posts

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

2 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

2 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

2 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

3 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

3 months ago

Common Practices for Laravel Blade Template

in this Laravel tutorial, I will explore common practices for using the Laravel Blade template with examples. Blade is a… Read More

3 months ago

Categories