How to configure php.ini for send mail in smtp

To configure PHP to send emails using SMTP, you'll need to modify the php.ini file. Here's a step-by-step guide:

Step 1: Locate the php.ini file

The location of the php.ini file varies depending on your operating system and PHP installation. Common locations include:

Step 2: Edit the php.ini file

Open the php.ini file in a text editor (e.g., Notepad, TextEdit, or Sublime Text).

Step 3: Configure the SMTP settings

Add the following lines to the php.ini file, replacing the placeholders with your actual SMTP server settings:

[mail function]
; For Win32 only.
SMTP = your_smtp_server
smtp_port = your_smtp_port
sendmail_from = your_from_email_address

Here's a breakdown of the settings:

Step 4: Save the changes

Save the php.ini file.

Step 5: Restart your web server

Restart your web server (e.g., Apache, Nginx, or IIS) to apply the changes.

Step 6: Test your email configuration

Create a PHP script to test your email configuration:

<?php
mail('[email protected]', 'Test Email', 'This is a test email');
?>

Run the script and check your email inbox to ensure that the email was sent successfully.

Additional tips: