Skip to content
Advertisement

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='https://pbs.twimg.com/profile_images/587949417577066499/3uCD4xxY_400x400.jpg'></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;"

Or:

style="background-color: blue;"

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

Advertisement

Answer

Because you are not escaping the " within the "

try:

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement