What are the differences between sending a HTML email and a text email in PHP?
When sending an email in PHP, you can choose to send it as either HTML or plain text. Sending an HTML email allows for formatting, images, and links to be included, while a text email is simpler and may be more compatible with all email clients. To send an HTML email in PHP, you need to set the appropriate headers and format the message content with HTML tags.
// Send an HTML email in PHP
$to = 'recipient@example.com';
$subject = 'HTML Email Test';
$message = '<html><body>';
$message .= '<h1>Hello!</h1>';
$message .= '<p>This is an HTML email sent from PHP.</p>';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Send the email
mail($to, $subject, $message, $headers);