What are the potential formatting issues when adding a boundary at the end of an email message in PHP?

Potential formatting issues when adding a boundary at the end of an email message in PHP include incorrect boundary syntax, missing boundary declaration, or improper placement of the boundary within the email body. To solve this issue, ensure that the boundary is properly declared and placed before the email content and that it follows the correct syntax.

$boundary = uniqid('boundary');

// Add boundary at the end of the email message
$message .= "\r\n--$boundary--";

// Set additional headers for multipart content
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"";