How to make mail sent confirmation message in php

To send a confirmation message after sending an email using PHP, you can use the following steps:

Step 1: Send the email using PHP

You can use the mail() function or a PHP mail library like PHPMailer to send the email. Here's an example using mail():

<?php
$to = '[email protected]';
$subject = 'Confirmation';
$message = 'Your email has been sent successfully!';
$headers = 'From: [email protected]'. "\r\n".
    'Reply-To: [email protected]'. "\r\n".
    'X-Mailer: PHP/'. phpversion();

if (mail($to, $subject, $message, $headers)) {
    // Email sent successfully
} else {
    // Email failed to send
}
?>

Step 2: Create a confirmation message

Create a PHP script that will send the confirmation message. This script will be triggered after the email is sent successfully.

Here's an example:

<?php
// Confirmation message script
$to = '[email protected]';
$subject = 'Email Sent Confirmation';
$message = 'Your email has been sent successfully!';

$headers = 'From: [email protected]'. "\r\n".
    'Reply-To: [email protected]'. "\r\n".
    'X-Mailer: PHP/'. phpversion();

if (mail($to, $subject, $message, $headers)) {
    // Confirmation message sent successfully
} else {
    // Confirmation message failed to send
}
?>

Step 3: Trigger the confirmation message script

In your original PHP script that sends the email, add a call to the confirmation message script after the email is sent successfully.

Here's an example:

<?php
// Original email sending script
$to = '[email protected]';
$subject = 'Confirmation';
$message = 'Your email has been sent successfully!';
$headers = 'From: [email protected]'. "\r\n".
    'Reply-To: [email protected]'. "\r\n".
    'X-Mailer: PHP/'. phpversion();

if (mail($to, $subject, $message, $headers)) {
    // Email sent successfully, trigger confirmation message
    include 'confirmation_message.php';
} else {
    // Email failed to send
}
?>

confirmation_message.php

<?php
// Confirmation message script
$to = '[email protected]';
$subject = 'Email Sent Confirmation';
$message = 'Your email has been sent successfully!';

$headers = 'From: [email protected]'. "\r\n".
    'Reply-To: [email protected]'. "\r\n".
    'X-Mailer: PHP/'. phpversion();

if (mail($to, $subject, $message, $headers)) {
    // Confirmation message sent successfully
} else {
    // Confirmation message failed to send
}
?>

In this example, the confirmation_message.php script is triggered after the email is sent successfully. This script sends a confirmation message to the recipient.

Note: Make sure to replace the email addresses and subject lines with your own values. Also, this is a basic example and you may want to add more functionality to your confirmation message script, such as logging the confirmation message or sending a copy to the sender.