Authenticatic mail script in php 7

Here is an example of an authenticatic mail script in PHP 7:

<?php

// Configuration
$smtp_host = 'smtp.example.com';
$smtp_port = 587;
$smtp_username = 'your_email_username';
$smtp_password = 'your_email_password';
$from_email = '[email protected]';
$to_email = '[email protected]';
$subject = 'Test Email';
$message = 'This is a test email sent using PHP 7.';

// Set the mail headers
$headers = array(
    'From' => $from_email,
    'Reply-To' => $from_email,
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8'
);

// Set the mail body
$body = $message;

// Create a new PHPMailer object
$mail = new PHPMailer\PHPMailer\PHPMailer();

// Set the SMTP server
$mail->isSMTP();
$mail->Host = $smtp_host;
$mail->Port = $smtp_port;
$mail->SMTPAuth = true;
$mail->Username = $smtp_username;
$mail->Password = $smtp_password;

// Set the mail sender and recipient
$mail->setFrom($from_email, 'Your Name');
$mail->addAddress($to_email, 'Recipient Name');

// Set the mail subject and body
$mail->Subject = $subject;
$mail->Body = $body;

// Send the mail
if (!$mail->send()) {
    echo 'Error sending mail: '. $mail->ErrorInfo;
} else {
    echo 'Mail sent successfully!';
}

?>

This script uses the PHPMailer library to send an email using SMTP. You'll need to install PHPMailer using Composer:

composer require phpmailer/phpmailer

Make sure to replace the placeholders (your_email_username, your_email_password, [email protected], [email protected], etc.) with your actual email credentials and recipient information.

Also, note that this script uses the isSMTP() method to set the mail transport to SMTP, and the SMTPAuth property to enable SMTP authentication. You may need to adjust these settings depending on your email provider's requirements.

Finally, make sure to check the PHPMailer documentation for more information on configuring and using the library.