How to display HTML email for preview on a web page?

I am trying to display a “preview” of an HTML email. I have HTML in my database, and now I need to display it in an iframe or popup or something like that. I am trying to inject html into the div tag on the page, but it will not display anything. Here is the problem I am facing (I have nested HTML tags):

<html>
    <body>
        <h1>My page</h1>
        <div id="email-body">
            <html>
                <body>
                    <p>email</p>
                </body>
            </html>
        </div>
    </body>
</html>
+3
source share
3 answers

You can write HTML in a popup.

var preview = window.open("", /* options */);
preview.document.write(html);
preview.document.close();

, , . , <body>. , . text/html HTML-, HTML <body>.

<p>email</p>

, - div .

, , <style>. .

<style>p { font-family: arial, sans-serif; }</style>
<p>email</p>

HTML . ( -!) .

+2

, , , ( , db):
$email = preg_replace('/\<\/?(html|body)\>/', '', $email);

. , <html> <body>, , <head>.

+1

This will not work because you cannot have two HTML structures in the document.

The only way I can do this that I see is to use iframe.

0
source

Source: https://habr.com/ru/post/1737606/


All Articles