How to use function php mail on wamp

To use the mail() function in PHP on WAMP (Windows, Apache, MySQL, PHP), you'll need to configure your PHP settings and WAMP environment. Here's a step-by-step guide:

Step 1: Check if the mail() function is enabled

Open your php.ini file, usually located in C:\wamp\bin\php\php5.6.25\php.ini (the path may vary depending on your WAMP version). Look for the following lines:

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

; For Win32 only.
; http://php.net/smtp
;smtp = localhost
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail
sendmail_path = "\"C:\wamp\bin\sendmail\sendmail.exe\" -t"

If the sendmail_path directive is commented out, uncomment it by removing the semicolon at the beginning of the line.

Step 2: Configure the sendmail.exe path

Make sure the sendmail.exe file is in the specified path: C:\wamp\bin\sendmail\sendmail.exe. If you've installed Sendmail elsewhere, update the sendmail_path directive accordingly.

Step 3: Restart WAMP

Restart your WAMP server to apply the changes. You can do this by stopping and starting the WAMP services or by restarting your computer.

Step 4: Test the mail() function

Create a PHP file with 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.';
  }
?>

Replace the [email protected] and [email protected] with your actual email addresses.

Step 5: Run the PHP file

Open a web browser and navigate to the PHP file you created. If everything is set up correctly, you should see the "Email sent successfully!" message.

That's it! You should now be able to use the mail() function in PHP on your WAMP environment.