How to send mail using wamp server

WAMP (Windows, Apache, MySQL, PHP) is a local development environment that allows you to run a web server on your Windows machine. To send mail using WAMP server, you'll need to configure your PHP settings and use a mail function. Here's a step-by-step guide:

Prerequisites:

  1. WAMP server installed on your Windows machine.
  2. PHP version 5.3 or higher.
  3. A mail server or a third-party SMTP service (e.g., Gmail, Outlook).

Step 1: Configure PHP settings

  1. Open the php.ini file in a text editor (e.g., Notepad++). You can find the file in the C:\wamp\bin\php\php5.x directory, where x is the version of PHP you're using.
  2. Search for the SMTP settings and update them as follows:
    • SMTP = your_smtp_server (e.g., smtp.gmail.com for Gmail)
    • smtp_port = 587 (or the port number used by your mail server)
    • smtp_auth = true
    • smtp_user = your_email_address (e.g., [email protected])
    • smtp_pass = your_email_password (e.g., your_password)
  3. Save the changes to the php.ini file.

Step 2: Use a mail function

You can use the mail() function in PHP to send mail. Here's an example:

<?php
$to = '[email protected]';
$subject = 'Test email from WAMP';
$message = 'This is a test email sent from WAMP server.';
$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.';
}
?>

Step 3: Test the mail function

  1. Create a new PHP file (e.g., sendmail.php) and paste the code above into it.
  2. Save the file in the C:\wamp\www directory (or any other directory that's accessible by your web server).
  3. Open a web browser and navigate to http://localhost/sendmail.php (or the URL of your PHP file).
  4. If everything is set up correctly, you should see the message "Email sent successfully!".

Troubleshooting tips:

By following these steps, you should be able to send mail using WAMP server.