普通网友 2016-06-15 03:05
浏览 24

服务器电邮问题

I am having trouble getting html to send via the mail() command on a php server. The email gets sent but the html code does not show up as html. How can I solve this. Below is the code I have the server send but it is not displaying as html in my mail browsers??

<html><table border="1"><tr><th>User Level</th><th>Number of Users</th></tr><tr><td>0</td><td>0</td></tr><tr><td>1</td><td>2</td></tr><tr><td>2</td><td>1</td></tr></table></html>

Below is how to get the content for the message

function get_tbl_lvl(){
$i=0;
$html .= '<table border="1"><tr><th>User Level</th><th>Number of Users</th></tr>';
while($i<3){
    $html .= '<tr><td>'.$i.'</td><td>';
    $num = num_level($i);
    if($num == -1){
        $html .= 'db fail';
    }else{
        $html .= $num;
    }
    $html .= '</td></tr>';
    $i++;
}
$html .= '</table>';
return $html;
}

Below is the code for sending the content

$msg = '<html>'.get_tbl_lvl().'</html>';
mail($to,$subject,$msg,$headers);
echo get_tbl_lvl();
  • 写回答

1条回答 默认 最新

  • dongshan9619 2016-06-15 03:15
    关注

    You have to set the html headers for it to work

      <?php
        $to = 'Someone@somewhere.com';
        $subject = 'Subject goes here';
        $message = '<html style="color:red">HTML Content HERE</html>';
        $headers  = 'MIME-Version: 1.0' . "
    ";
        //This is where you let it be known it's html
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    
        // Mail it
        mail($to, $subject, $message, $headers);
    
    评论

报告相同问题?