What are the steps involved in changing the Content-Type header in PHP to send email content as HTML?
When sending emails in PHP, the default Content-Type header is usually set to plain text. To send email content as HTML, you need to change the Content-Type header to "text/html". This can be done by setting the appropriate header in the mail function or using a library like PHPMailer.
<?php
$to = "recipient@example.com";
$subject = "HTML Email Test";
$message = "<h1>This is a test email</h1><p>This email is being sent as HTML content.</p>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Send email
mail($to, $subject, $message, $headers);
?>
Keywords
Related Questions
- How can attributes be added to a PHP newsletter management system like PHPList?
- In what ways can server-side configurations, such as the session save path, impact the behavior of PHP sessions and the storage of session data?
- What alternative approaches can be used to achieve the desired outcome without relying on header() after setting a cookie in PHP?