How can one ensure proper message formatting, such as ending with a single point, when sending emails via SMTP in PHP?

When sending emails via SMTP in PHP, one can ensure proper message formatting by correctly structuring the email headers and body. To end the message with a single point, use "\r\n.\r\n" after the message content. This signals the end of the email body and ensures that the email is formatted correctly.

// Define email headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: sender@example.com\r\n";

// Define email body
$message = "This is the email message content.\r\n";
$message .= "Make sure to end with a single point.\r\n";
$message .= "\r\n.\r\n"; // End the message with a single point

// Send email using SMTP
$success = mail("recipient@example.com", "Subject", $message, $headers);
if($success) {
    echo "Email sent successfully";
} else {
    echo "Email sending failed";
}