How can variables be efficiently inserted into email templates in PHP without using a separate template file?

To efficiently insert variables into email templates in PHP without using a separate template file, you can use heredoc syntax to create the email template directly within your PHP code. This allows you to easily insert variables using curly braces within the template string.

<?php

// Define variables
$name = "John Doe";
$email = "johndoe@example.com";

// Create email template using heredoc syntax
$emailTemplate = <<<EOT
Hello {$name},

Thank you for your inquiry. We will respond to you at {$email} as soon as possible.

Best regards,
Your Company
EOT;

// Send email using $emailTemplate
// mail($email, "Response to Inquiry", $emailTemplate);