How to configure php.ini file to send a mail

To configure the php.ini file to send an email, you'll need to set the following settings:

  1. SMTP Server: Set the SMTP directive to the name or IP address of your SMTP server. For example:
    SMTP = your_smtp_server.com
  2. SMTP Port: Set the smtp_port directive to the port number used by your SMTP server. For example:
    smtp_port = 587
  3. Email Address: Set the sendmail_from directive to the email address you want to use as the "From" address. For example:
    sendmail_from = [email protected]
  4. Authentication: If your SMTP server requires authentication, set the smtp_auth directive to 1 and provide the username and password in the smtp_username and smtp_password directives, respectively. For example:
    smtp_auth = 1
    smtp_username = your_smtp_username
    smtp_password = your_smtp_password
  5. Encryption: If your SMTP server uses encryption (e.g., SSL/TLS), set the smtp_ssl directive to 1. For example:
    smtp_ssl = 1

    Here's an example of what the php.ini file might look like with these settings:

    [mail function]
    SMTP = your_smtp_server.com
    smtp_port = 587
    sendmail_from = [email protected]
    smtp_auth = 1
    smtp_username = your_smtp_username
    smtp_password = your_smtp_password
    smtp_ssl = 1

    After making these changes, save the php.ini file and restart your web server or PHP-FPM service to apply the changes.

You can also use the mail() function in your PHP script to send an email. For example:

<?php
mail('[email protected]', 'Subject', 'Hello, world!');
?>

Make sure to replace your_smtp_server.com, [email protected], your_smtp_username, and your_smtp_password with your actual SMTP server, email address, username, and password, respectively.