How can PHP variables be properly displayed in email subjects using mailto?

When using the mailto function in PHP to send emails, variables can be properly displayed in email subjects by concatenating them within the subject parameter. This can be achieved by enclosing the variable within double quotes and using the dot (.) operator to concatenate it with the rest of the subject string.

$email = "recipient@example.com";
$subject = "Hello " . $name . ", this is the subject of the email";
$body = "This is the body of the email";

$mailTo = "mailto:" . $email . "?subject=" . urlencode($subject) . "&body=" . urlencode($body);

header("Location: $mailTo");