What is the potential issue with using the provided PHP script for sending emails from a contact form?

The potential issue with the provided PHP script is that it is vulnerable to email injection attacks. To solve this issue, you should sanitize user input before using it in the email headers to prevent malicious code injection.

// Sanitize user input to prevent email injection
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

// Set email headers
$headers = "From: $name <$email>" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

// Send email
$to = "your_email@example.com";
$subject = "Contact Form Submission";
$mailBody = "Name: $name <br>Email: $email <br>Message: $message";
$mailSent = mail($to, $subject, $mailBody, $headers);

if ($mailSent) {
    echo "Email sent successfully";
} else {
    echo "Failed to send email";
}