How can i send mail in php

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

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

mail($to, $subject, $message, $headers);
?>

This code sends an email to the recipient at [email protected] with the subject "Test email" and the message "This is a test email sent from PHP". The headers variable is used to set the from address, reply-to address, and content type of the email.

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 'PHPMailer/PHPMailer.php';
require '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->setFrom('[email protected]', 'Your Name');
$mail->addAddress('[email protected]', 'Recipient Name');
$mail->Subject = 'Test email';
$mail->Body = 'This is a test email sent from PHP';

$mail->send();
?>

This code sends an email using the PHPMailer library, which allows you to specify the SMTP server, username, password, and other settings.

Note that in both examples, you need to replace the placeholders ([email protected], [email protected], etc.) with the actual email addresses and settings you want to use.

Also, keep in mind that the mail() function is a built-in function in PHP, but it may not work correctly on all servers, especially if the server has strict security settings. In that case, you may need to use a third-party library like PHPMailer to send emails.