How can PHP variables be properly concatenated to create a single string for email content?

When concatenating PHP variables to create a single string for email content, you can use the concatenation operator (.) to combine the variables with any necessary text or HTML tags. Make sure to properly format the string with line breaks (\n) or HTML line breaks (<br>) for readability in the email content. Additionally, sanitize any user input to prevent injection attacks.

// Example of concatenating PHP variables for email content
$emailSubject = &quot;New message from &quot; . $name;
$emailBody = &quot;Hello &quot; . $name . &quot;,\n\n&quot;;
$emailBody .= &quot;Thank you for your message. Here is the content:\n\n&quot;;
$emailBody .= &quot;Message: &quot; . $message;

// Send email using PHP&#039;s mail function
mail($to, $emailSubject, $emailBody, $headers);