How can incorrect line breaks in email headers affect the delivery of HTML emails sent using PHP mail() function?
Incorrect line breaks in email headers can cause the email to be rejected or marked as spam by the recipient's email server. To solve this issue, make sure that each header in the email is properly formatted with \r\n line breaks.
<?php
$to = "recipient@example.com";
$subject = "Test Email";
$message = "<html><body><h1>Hello, World!</h1></body></html>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: sender@example.com\r\n";
mail($to, $subject, $message, $headers);
?>
Keywords
Related Questions
- Are there any potential pitfalls to be aware of when using PHP to output data in a table format?
- What are best practices for comparing the number of header fields with the number of data fields in a CSV file using PHP?
- In what situations should developers consider switching from MySQL to PDO in PHP?