What best practices should be followed when designing HTML emails for PHP mail function?
When designing HTML emails for the PHP mail function, it is important to ensure that the email content is properly formatted and styled to display correctly in various email clients. This includes using inline CSS, providing alternative text for images, and testing the email in different email clients to ensure compatibility.
<?php
$to = "recipient@example.com";
$subject = "HTML Email Test";
$message = "
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
color: #333;
}
</style>
</head>
<body>
<h1>Hello!</h1>
<p>This is a test email with HTML content.</p>
</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);
?>