Php mail function test

The classic PHP mail function!

To test the PHP mail function, you can use the following code:

<?php
  $to = '[email protected]'; // replace with the recipient's email address
  $subject = 'Test Email from PHP';
  $message = 'This is a test email sent from PHP.';

  // Set the headers
  $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';

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

Here's what you need to do:

  1. Replace [email protected] with the email address you want to send the test email to.
  2. Replace [email protected] with the email address you want to use as the sender.
  3. Save the code in a PHP file (e.g., test_email.php) and upload it to your web server.
  4. Open a web browser and navigate to the PHP file (e.g., http://example.com/test_email.php).
  5. If everything is set up correctly, you should see the message "Email sent successfully!".

If you don't see the success message, there might be an issue with your PHP configuration or email setup. Here are some common issues to check: