How to sedn mail using php

In PHP, you can send an email using the mail() function, which is a built-in function in PHP. Here is a basic example of how to use it:

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

In this example, we define the recipient's email address, the subject of the email, the message body, and the headers. The headers include the sender's email address, the reply-to address, and the MIME version and content type.

The mail() function takes four arguments: the recipient's email address, the subject, the message body, and the headers. If the email is sent successfully, the function returns true, otherwise it returns false.

You can also use the PHPMailer library, which is a popular and powerful email sending library for PHP. Here is an example of how to use it:

<?php
  require_once 'PHPMailer/PHPMailer.php';
  require_once 'PHPMailer/SMTP.php';

  $mail = new PHPMailer\PHPMailer\PHPMailer();
  $mail->isSMTP();
  $mail->Host = 'smtp.example.com';
  $mail->SMTPAuth = true;
  $mail->Username = '[email protected]';
  $mail->Password = 'your_password';
  $mail->SMTPSecure = 'tls';
  $mail->Port = 587;

  $mail->setFrom('[email protected]', 'Your Name');
  $mail->addAddress('[email protected]', 'Recipient Name');
  $mail->Subject = 'Test email';
  $mail->Body = 'This is a test email sent using PHPMailer';

  if ($mail->send()) {
    echo 'Email sent successfully!';
  } else {
    echo 'Error sending email!';
  }
?>

In this example, we create a new instance of the PHPMailer class and set up the SMTP settings. We then set the sender's email address and name, the recipient's email address and name, the subject, and the message body. Finally, we call the send() method to send the email.

Note that you need to install the PHPMailer library and configure it according to your email server settings.