How to check php mail function is working or not

There are several ways to check if the PHP mail function is working or not:

  1. Send a test email: Use the PHP mail function to send a test email to yourself or a colleague. You can use the following code:
    
    <?php
    $to = '[email protected]';
    $subject = 'Test Email';
    $message = 'This is a test email sent using PHP mail function.';

$headers = 'From: [email protected]'. "\r\n". 'Reply-To: [email protected]'. "\r\n". 'MIME-Version: 1.0'. "\r\n". 'Content-Type: text/plain; charset=UTF-8';

if (mail($to, $subject, $message, $headers)) { echo 'Email sent successfully!'; } else { echo 'Error sending email!'; } ?>

If the email is sent successfully, you should receive it in your inbox. If not, you may need to check the email settings or the PHP configuration.

2. **Check the PHP error log**: PHP logs errors and warnings in a file, usually located at `error_log` or `php_errors.log`. Check this file for any errors related to the mail function. You can also use the `error_reporting` and `ini_set` functions to enable error reporting:
```php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Your mail function code here
?>
  1. Use a mail testing tool: There are several online tools available that can help you test the PHP mail function. Some popular options include:
    • Mail Tester: A simple online tool that sends a test email to your specified email address.
    • PHP Mail Tester: A more advanced tool that allows you to test the PHP mail function with different settings and configurations.
  2. Check the mail server logs: If you're using a mail server like Sendmail, Postfix, or Exim, you can check the logs to see if the email is being sent successfully. The logs are usually located at /var/log/mail.log or /var/log/exim4.log.
  3. Use a PHP mail wrapper library: There are several PHP libraries available that provide a wrapper around the PHP mail function, making it easier to send emails and debug any issues. Some popular options include:
    • PHPMailer: A popular library that provides a simple and easy-to-use interface for sending emails.
    • SwiftMailer: Another popular library that provides a more advanced and flexible way of sending emails.

By using one or more of these methods, you should be able to determine if the PHP mail function is working or not.