How can strings be concatenated in PHP to create a message body for the mail() function?

To concatenate strings in PHP for creating a message body for the mail() function, you can use the dot (.) operator to combine multiple strings into one. This allows you to construct a customized message by combining static text with dynamic variables or values. Make sure to properly format the message body with line breaks or HTML tags if needed for better readability.

// Example of concatenating strings for creating a message body for the mail() function
$to = "recipient@example.com";
$subject = "Test Email";
$message = "Hello, " . $username . "! This is a test email.";
$message .= "\n\nPlease let us know if you have any questions.";
$headers = "From: sender@example.com";

// Send email using mail() function
mail($to, $subject, $message, $headers);