3

Currently I have a script that send some mail, the script result are a couple html tables:

$from = "prueba.com <noreply@prueba.com>"; 
$to = "myemail@gmail.com"; 
echo "<div>"; 

$contenido = ob_get_contents(); 
echo "</div>"; 
$cabeceras = "Content-type: text/html; charset=iso-8859-1 \r\n" 
           ."MIME-Version: 1.0 \r\n" 
           ."To: $cliente <$email> \r\n" 
           ."From: prueba <prueba@example.com> \r\n"; 

mail($to,$subject,$contenido,$cabeceras); 

ob_end_flush(); 

As might give css to that email? as I have tried several methods and none has worked.

Thanks in advance for your cooperation

EDIT:

THIS is my CODE http://www.mediafire.com/?bq9352xh6paji1d

JuanFernandoz
  • 805
  • 17
  • 40
  • 1
    Whats in your $contenido ??? You need to specify css inline – jtheman Sep 02 '12 at 21:42
  • $contenido is the result of making file_get_contents into an array (several files with glob function) and using strip_tags. The result is some html tables (one html table for file). – JuanFernandoz Sep 02 '12 at 21:45
  • Yes but if you want to style the html either add a HEAD sectiion with the css or att the styling inline as style="" ... – jtheman Sep 02 '12 at 21:51
  • Already tried that but for some reason the mail result don't admit any css rule. – JuanFernandoz Sep 02 '12 at 21:54
  • You are leaving out the important in your question, you need to provide whats in the output buffer... And I guess you would be helped by using a template to put the contents inside... – jtheman Sep 02 '12 at 22:03
  • I don't think you understand the difference between html for a web page and html for email –  Sep 02 '12 at 22:11

2 Answers2

3

Maybe you wanted like this: (using ob_get_clean())

ob_start();
echo "<div>"; 
    // more html
echo "</div>";
$contenido = ob_get_clean(); 

and lose the last ob_end_flush();

TEST:

$from = "prueba.com <noreply@prueba.com>"; 
$to = "myemail@gmail.com"; 
ob_start();
echo "<div>"; 
echo "<table border='1'><tr><td>TEST</td></tr></tr>";
echo "</div>";
$contenido = ob_get_clean(); 

$cabeceras = "Content-type: text/html; charset=iso-8859-1 \r\n" 
           ."MIME-Version: 1.0 \r\n" 
           ."To: $cliente <$email> \r\n" 
           ."From: prueba <prueba@example.com> \r\n"; 

mail($to,$subject,$contenido,$cabeceras); 
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
0

You might take a read here: http://css-tricks.com/sending-nice-html-email-with-php/

Gianpaolo Di Nino
  • 1,139
  • 5
  • 17