I want to convert a web pages which is heavily CSS styled is written in PHP to static html so that I can embed it in an email.
I have managed to do this but for achieving this I had to convert the whole page into a string and then assign that string as email body. The layout of the page does not look as good as original as I have not been able embed CSS.
This approach has a few problems like if any changes have to be made to the layout of the page I have to redo the whole process for generating an embeddable page.
I want an easier way which will allow me to keep the original page editable in Dreamweaver visually.
You can use output buffers. If you have an html page, such as:
<html>
<head>
<title>Blah</title>
</head>
<body>
Some text here
</body>
</html>
Then if you put, at the top of the html file:
<?php ob_start(); ?>
And right at the bottom, after the last tag, put:
<?php
$string = ob_get_contents();
//do whatever you need to do to the html, save it to a seperate file, email it, etc
ob_flush();
?>
What this basically means is that the $string variable will end up with the entire static html of the page, after it has been dynamically generated. You can then use that string in an email. Although really, html pages don't work exactly the same in emails, so you may want to rethink the approach.
This is a hard thing to do automatically for several reasons:
So there are various ways you could do this like using cURL to get the Webpage, using output buffering to capture the page by using require/include, etc but all these methods suffer from one or more of the above problems. I've generally found the only way to do HTML email is to hand-roll it.
just do this in php page
Put this on top for where you want to start capturing output:
ob_start();
put this on the bottom of the php
$HtmlCode= ob_get_contents(); ob_end_flush();
$fh=fopen('index.html','w'); fwrite($fh,$HtmlCode);
fclose($fh);
then redirect to html page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With