3 replies
Trying to send a HTML email with PHP mail (I know thats not the best way but it still should work)

Code:
$headers = "MIME-Version: 1.0" . "\r\n";
  $headers = $headers."Content-type:text/html;charset=iso-8859-1" . "\r\n";
  $headers = $headers."From:".$EmailFrom."\r\n";
  
  $to=$EM;
  $subject=$EmailSubject;
  $message='<html><body>'.stripslashes(trim($WinMessage)).'</html></body>';

// Mail it
mail($to, $subject, $message, $headers);
the varable $WinMessage contains the string:

<p style="text-align: center;"> <span style="font-size:26px;"><strong>Good for you you won something .. whoopp whooop</strong></span></p>


The mail sends fine however it displays as plain text. If I remove the varable from the code: (remove stripslashes(trim($WinMessage)); and replace it with the string that the variable contains it displays fine. Can anyone identify why the mails body displays as a sting and not as HTML when I use the variable?
#assistance #html #mail
  • Profile picture of the author h4x0r
    Most of the mails dont allow html or body tags, my guess is to try only with body tag and without html and body tag
    {{ DiscussionBoard.errors[8508025].message }}
  • Profile picture of the author brutecky
    Solved:

    Variable was the result of a DB call and needed to decode the HTML entities.

    Code:
    ='<html><body>'.stripslashes(trim(html_entity_decode())).'</html></body>';
    {{ DiscussionBoard.errors[8508051].message }}
  • Profile picture of the author hngems
    use mail function of php mail($to, $subject, $message, $headers);
    The last parameter, the headers, are optional for the function but required for sending HTML email, as this is where we are able to pass along the Content-Type declaration telling email clients to parse the email as HTML.
    And you can use header as follows
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    {{ DiscussionBoard.errors[8517525].message }}

Trending Topics