What is the recommended method for sending variables via email in PHP?

When sending variables via email in PHP, it is recommended to use the PHP `mail()` function along with headers to properly format the email content. This ensures that the variables are correctly passed and displayed in the email. Additionally, it is important to properly sanitize and validate the variables to prevent any security vulnerabilities.

<?php
$to = 'recipient@example.com';
$subject = 'Example Subject';
$message = 'Hello, this is an example email with variables: ';
$message .= 'Variable 1: ' . $variable1 . "\r\n";
$message .= 'Variable 2: ' . $variable2 . "\r\n";

$headers = 'From: sender@example.com' . "\r\n" .
    'Reply-To: sender@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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