PHP mail formatting

Discussion in 'PHP' started by Weirfire, Jan 16, 2006.

  1. #1
    Basic question - how do I send an email with css formatting?

    I've been trying to mail something along the lines of the example below;


    $message = "<table width='450' style='background: green'>";
    $message = "<tr><td style='color: #E0E0E0'>I'm green and slimey</td></tr>";
    $message = "</table>";

    mail($email, $subject, $message, $mailheaders);

    It doesnt seem to do anything within the quotes e.g. width='450' or style='....'

    Do I need to set up the type of email in the $message variable?
     
    Weirfire, Jan 16, 2006 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The following works for me:

    
    $subject = "title";
    $message = "
    <html>
    <head>
    <LINK REL=\"StyleSheet\" HREF=\"http://www.domain.org.uk/style.css\" TYPE=\"text/css\">
    </head>
    <body>
    <table><tr><td class=\"content\" colspan=3>
    content
    </td></tr>
    </table>
    </body>
    </html>
    ";
    
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: no-reply@domain.org.uk <no-reply@domain.org.uk>\r\n"; 
    
    mail("$to", $subject, $message, $headers);
    
    PHP:
    Alternatively you could try adding a \ before your ' eg width=\'400\'

    Also you should use an inline style sheet rather than an external one like I do.
     
    dave487, Jan 16, 2006 IP
  3. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Thanks Dave, I'll try that!
     
    Weirfire, Jan 16, 2006 IP