Home >Backend Development >PHP Tutorial >How to Resolve HTML Display Issues When Using PHPmailer
Problem Statement:
When using PHPmailer to send emails with HTML content, the actual HTML code appears in the email body instead of the desired content.
Solution:
To resolve this issue, the isHTML() method should be called after setting the Body property of the PHPmailer instance:
<code class="php">$mail->Subject = $Subject; $mail->Body = $Body; $mail->isHTML(true); // Call isHTML() after $mail->Body has been set</code>
Explanation:
The isHTML() method sets the email format to HTML. However, if it is called before the Body property is set, the HTML content is not recognized, resulting in the display of the actual code in the email body.
By calling isHTML() after setting Body, PHPmailer is informed that the email should be formatted as HTML and the desired content is displayed correctly.
The above is the detailed content of How to Resolve HTML Display Issues When Using PHPmailer. For more information, please follow other related articles on the PHP Chinese website!