Mail sender php

Here is an example of a PHP script that sends an email using the mail() function:

<?php

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

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

?>

This script defines the email settings, including the recipient's email address, subject, message, and headers. It then uses the mail() function to send the email. If the email is sent successfully, it displays a success message. If there is an error, it displays an error message.

You can also use PHPMailer library which is more powerful and flexible 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->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!';
} else {
    echo 'Email sent successfully!';
}

?>

You can also use SwiftMailer library which is another popular PHP email library.

<?php

require 'SwiftMailer/Swift.php';

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

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

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

?>

Make sure to install the required libraries and configure them according to your email settings.