How can HTML tags be utilized for formatting in PHP mail texts?

When sending emails using PHP's mail function, HTML tags can be utilized for formatting the text within the email. This allows for styling the content, such as adding headings, paragraphs, links, and other formatting options. To include HTML tags in the email content, the message parameter of the mail function needs to be set as a MIME type of "text/html" to inform the email client that the content is formatted as HTML.

$to = 'recipient@example.com';
$subject = 'HTML formatted email';
$message = '<html><body>';
$message .= '<h1>Hello!</h1>';
$message .= '<p>This is an example of an HTML formatted email sent via PHP.</p>';
$message .= '</body></html>';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

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