How can HTML and CSS impact the functionality of a PHP script for sending emails?
HTML and CSS can impact the functionality of a PHP script for sending emails by affecting the layout and styling of the email content. To ensure that the email is displayed correctly across different email clients, it is important to use inline CSS styles and avoid relying on external stylesheets. Additionally, using HTML tables for layout can help maintain consistency in the email design.
<?php
$to = "recipient@example.com";
$subject = "Test Email";
$message = "
<html>
<head>
<style>
/* Inline CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
</style>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a test email.</p>
</body>
</html>
";
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: sender@example.com' . "\r\n";
// Send email
mail($to, $subject, $message, $headers);
?>
Related questions
-
DOMDocument DOMXPath regular expressions
-
SQL injections PHP code databases
-
PHP include function file path