Php mail send

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

<?php
// Define the email settings
$to = '[email protected]';
$subject = 'Test Email';
$message = 'This is a test email sent using PHP.';

// Define the email headers
$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';

// Send the email using the mail() function
mail($to, $subject, $message, $headers);

// Check if the email was sent successfully
if (mail($to, $subject, $message, $headers)) {
    echo 'Email sent successfully!';
} else {
    echo 'Error sending email!';
}
?>

This code uses the mail() function to send an email to the specified recipient. The mail() function takes four arguments:

You can also use the PHPMailer library to send emails, it's a popular and powerful library that provides more features and flexibility than the built-in mail() function.

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

$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$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 using PHPMailer.';

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

You can also use the SwiftMailer library, it's another popular library that provides more features and flexibility than the built-in mail() function.

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

$mail = new Swift_Mailer();
$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 SwiftMailer.';

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

Please note that you need to configure your email settings correctly, such as the SMTP server, port, username, and password, to send emails using these libraries.

Also, you can use the Zend_Mail library, it's a popular library that provides more features and flexibility than the built-in mail() function.

<?php
require 'Zend/Mail.php';

$mail = new Zend_Mail();
$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 Zend_Mail.';

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

Please note that you need to configure your email settings correctly, such as the SMTP server, port, username, and password, to send emails using these libraries.