Are there best practices for ensuring that data passed through HTML forms in emails is not lost?

When passing data through HTML forms in emails, it is important to ensure that the data is not lost due to email clients stripping out certain HTML elements or formatting. To prevent this, one best practice is to encode the data before including it in the email to ensure it is properly displayed.

// Encode the data before including it in the email
$data = htmlentities($_POST['data']);

// Construct the email message with the encoded data
$message = "Data from form: " . $data;

// Send the email with the encoded data
mail('recipient@example.com', 'Form Data', $message);