How can a confirmation email be sent simultaneously to the sender when using a PHP email form?

To send a confirmation email simultaneously to the sender when using a PHP email form, you can use the "CC" header in the PHP mail() function to send a copy of the email to the sender's email address. This way, the sender will receive a confirmation email along with the email sent to the recipient.

<?php
$to = "recipient@example.com";
$subject = "Subject of the email";
$message = "This is the message content";

$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "CC: sender@example.com\r\n";

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