dajuric
dajuric

Reputation: 2507

Mailing HTML content with PHP

I would like to mail the content of a Web page that looks like:

<html>

   <body>

   <?php

     function sendPageContentToEmail($destEmail)
     {   
       ob_start();
       $buffer = ob_get_contents();
       ob_end_clean();

       $subject = 'Subject name';

       mail($destEmail, $subject, $buffer);
      }
  ?>

    <div style="width:400px; margin:0 auto;">

   <p>
        Name: <?php print($customerData['customer_name']); ?>
       </p>

   <p>
         ....
       </p>

 </div>


 </body>
 </html>

   <?php 

    sendPageContentToEmail($customerData['customer_email']);

    //erase all temp data
    session_destroy();
   ?>

$buffer is always empty (ob_get_content()) regardless of where the sendPageContentToEmail() is called. Where should this function be called (assuming that it is the right way to do it)?

Upvotes: 0

Views: 99

Answers (1)

elvena
elvena

Reputation: 421

What ob_start does is start caching all the output, so, if you output something before calling it, that part won't be cached.

Just at the start, before <html> do a <?php ob_start(); ?>

Upvotes: 2

Related Questions