Skip to content

Is it possible to add CSS in the Mail function in PHP?

I want to add some css in the Mail function to this code:

$text .= "<h1>Confirmation Code</h1>";
$text .= "<img src=''></img>";
$text .= "<h3>This is your confirmation code. Enter it into the text box in World Web. Here is the code: '".$_REQUEST['random_num']."'</h3>";
$text .= "<h4>Thank you for working with WWW. We appreciate the help!</h4>";
$text .= "</body></html>";
$subject = "Confirmation Code";
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=UTF-8" . "rn";
$to = $_REQUEST['email'];
mail($to, $subject, $text, $headers);

But when I add:

style="color: red;"


style="background-color: blue;"

It errors out. Anybody know how I can add css to the mail function in php?


Because you are not escaping the " within the "


$text .= "<h1 style='color:red;'>Confirmation Code</h1>";
$text .= "<h1 style="color:red;">Confirmation Code</h1>";