Are there any best practices to follow when including images or styling in HTML emails sent via PHP?

When including images or styling in HTML emails sent via PHP, it's important to use absolute URLs for images and inline styles for styling to ensure proper rendering across email clients. Additionally, it's recommended to use a MIME type of "multipart/alternative" to include both HTML and plain text versions of the email for better compatibility.

// Example PHP code snippet for sending an HTML email with images and styling
$to = "recipient@example.com";
$subject = "HTML Email with Images and Styling";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$message = "
<html>
<head>
<style>
  p {
    color: #333;
    font-size: 16px;
  }
</style>
</head>
<body>
<p>This is an HTML email with images and styling:</p>
<img src='https://example.com/image.jpg' alt='Image' style='width: 100px; height: auto;'>
</body>
</html>
";

// Send the email
mail($to, $subject, $message, $headers);