Send mail through php

Here is an example of how to send an email using PHP:

Using the mail() function

<?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';

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

This code uses the mail() function to send an email to the specified recipient. The $headers variable is used to set the from, reply-to, and content-type headers.

Using a PHPMailer class

<?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->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 'Error sending email: '. $mail->ErrorInfo;
} else {
    echo 'Email sent successfully!';
}
?>

This code uses the PHPMailer class to send an email. You need to install the PHPMailer library and require it in your PHP file. The code sets up the SMTP server, authentication, and email details, and then sends the email.

Using SwiftMailer

<?php
require 'SwiftMailer/Swift.php';

$mail = new Swift_Mailer(new Swift_SendmailTransport());

$message = Swift_Message::newInstance()
    ->setSubject('Test email')
    ->setFrom(array('[email protected]' => 'Your Name'))
    ->setTo(array('[email protected]' => 'Recipient Name'))
    ->setBody('This is a test email sent using SwiftMailer.');

$mail->send($message);
?>

This code uses the SwiftMailer library to send an email. You need to install the SwiftMailer library and require it in your PHP file. The code creates a new Swift_Message object and sets the subject, from, to, and body of the email, and then sends the email using the Swift_Mailer object.

Make sure to replace the placeholders (e.g. smtp.example.com, [email protected], your_password) with your actual email server settings and credentials.