如何让“From”代码使用PHP邮件与电子邮件的HTML正文一起使用?

Here is the interesting part, if I remove the $from code, it will properly render the html email like it supposed too. If I add the $from code back in, the $from will work properly but show the entire html script code in the body of the email. I am trying to figure out how to get the from and the html email to work properly together. I have tried the and but nothing works. It's one or the other with this code.

$from    = 'MyOwnEmail';
$to      = $email;
$subject = 'Test ';
$message_body = '<html><html>';

$headers = 'MIME-Version: 1.0';
$headers = 'Content-type: text/html; charset=iso-8859-1';
$headers = "From: $from"; 
mail( $to, $subject, $message_body, $headers);
 $headers = 'MIME-Version: 1.0';
 $headers = 'Content-type: text/html; charset=iso-8859-1';
 $headers = "From: $from";

Each time you assign a new value to $headers, you replace the old value.

So you need to look up how to put multiple headers into the variable. See the documentation for the additional headers:

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF ( ). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.

So you still need a string, but it has to be one string with all the headers in it, and the need to be separated by new lines.

The cleanest way to do this would be to put all the headers in an array and then join them.

$header_list = [ 'MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1', "From: $from" ];
$header = implode("
", $header_list);

Append headers instead of overwriting.

$headers = 'MIME-Version: 1.0'."
";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."
";
$headers .= "From: $from"."
";

Solution - Fixed with Quentin Help -- Thanks

$from    = 'MyOwnEmail';
$to      = $email;
$subject = 'Test ';
$message_body = '<html></html>';

$header_list = [ 'MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1', "From: $from" ];
$header = implode("
", $header_list);

mail( $to, $subject, $message_body, $header);