HTML Mail assistance

by 3 replies
4
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:

#programming #assistance #html #mail
  • 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
  • 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>';
  • 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";

Next Topics on Trending Feed

  • 4

    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: