What are common pitfalls when trying to format and send an HTML list via PHP email?
Common pitfalls when trying to format and send an HTML list via PHP email include not properly formatting the HTML content, not setting the correct headers for the email, and not encoding special characters. To solve these issues, make sure to properly format the HTML content with the list tags, set the appropriate headers for sending HTML content, and use functions like htmlspecialchars() to encode special characters.
<?php
$to = "recipient@example.com";
$subject = "HTML List Email";
$message = "
<html>
<head>
<title>HTML List Email</title>
</head>
<body>
<h1>Here is a list:</h1>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to, $subject, $message, $headers);
?>