How to send html table in email body in php?

后端 未结 4 883
天涯浪人
天涯浪人 2020-12-11 07:09

I am sending dynamically creating html table in email body but in the email I receive the html code instead of displaying a table. Please help me. Here is my code.



        
4条回答
  •  孤城傲影
    2020-12-11 07:34

    First you are missing the tag in your HTML code but that should not be an issue.

    Secondly your header is incorrect, you have that:

    $headers = "From Ahmad \r\n";
    //$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
    //$headers .= "CC: susan@example.com\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
    $subject = 'Email report';
    

    instead of:

    //$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
    //$headers .= "CC: susan@example.com\r\n";
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
    $headers .= "From: Ahmad \r\n";
    $subject = 'Email report';
    

    Basically I think you header should start by "Mime-Version".

    Check this code: http://us.php.net/manual/en/function.mail.php#example-2877

提交回复
热议问题