Earlier post explained on how to send a plain email using PHP. This time, we are discussing about sending page contents to email. This technique is based on output buffering. Basically, it would first create read a html file and store in buffer using ob_start(). Next step is to include desire HTML page using include function and then store the contents of that HTML page using ob_get_contents(). Finally use mail() function to send email.
While output buffering is turned on no output is sent from then script. The output is stored in an internal buffer.
<?php ob_start(); include_once("samplepage.html"); $buffer = ob_get_contents(); ob_end_clean(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.SENDER_NAME.' <'.SENDER_EMAIL.'> ' . "\r\n"; $to_email = 'firstname.lastname@example.org'; $subject = 'Your Desired Email Subject'; mail($to_email, $subject, $buffer, $headers); ?>