hi first post.

I'm trying to use the mail() function in php to send an html email. The mail script is basically:

<?php

$to = "info@example.com";
$subject = "Subject";

$body = "<h1 id='bodyheadline'>body</h1>";
$body .= "<p class='bodytext'>more body</p>";

$header = "From: $email\n";
$header .= "Reply-To: $email\n";
$header .= "Content-type: text/html\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";

mail($to, $subject, $body, $header);

?>

Pretty straight forward. Is it possible to include or link to a stylesheet with the classes and id's used in the $body, or do styles have to be inline. I've tried include() require_once() and even break out of <?php ?> and using <link> tags. Unfortunately I can't seem to get the style's to carry into the sent email.

Thanks

    No, the styles do not need to be inline. But if they arent, they must be attached to the mail. You can link to outside but mail programs wont load the css file and will warn you about it.

    Include and require_once arent gonna work here and you obviously dont know what they do, so Im gonna recommend using ready made mail library that will suit you fine:
    Mimemail

    With mimemail you can easily attach even images automatically to your messages.

    If you are just sending HTML mail with no pictures, you can just put the style markup straight to message. Like:

    $body= '<style type="text/css">.bodytext { color: #5f5;}</style>';
    

      thanks for the reply cahva, appreciate the help if not the smug put down.

        Write a Reply...