How can PHP mail headers be utilized to send HTML-formatted emails?
To send HTML-formatted emails using PHP, you can utilize the mail headers to specify the content type as text/html. This tells the email client to interpret the email content as HTML code rather than plain text. By setting the appropriate headers, you can ensure that your HTML content is rendered correctly in the recipient's email client.
$to = 'recipient@example.com';
$subject = 'HTML Email Test';
$message = '<html><body>';
$message .= '<h1>Hello, this is an HTML email!</h1>';
$message .= '<p>This is a test email sent using PHP.</p>';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: sender@example.com' . "\r\n";
mail($to, $subject, $message, $headers);