0

HTMLコードに対応できる電子メールメッセージを送信するための小さなコードがあります。hotmail ではメッセージは完全に表示されますが、gmail ではすべての html コードがテキストと見なされて表示されるだけでした。

以下はコード形式です:-

$headers        = "From: $from \r\n <$email_return>"; 
$headers        .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

ob_get_contents(); ?> 
--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/plain; charset="utf-8" 
Content-Transfer-Encoding: 7bit

<?php echo $email_message;?>

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="utf-8" 
Content-Transfer-Encoding: 7bit

<div style="text-align:left;"><img src="sitelogo.png" height="50px;"></div>
<br>
Dear <?php echo $name;?>,
<br><br>
Thanks!

<br><br><br>
<strong><i><?php echo $email_signature;?></i></strong><br><br>

--PHP-alt-<?php echo $random_hash; ?>-- 

<?php 
$message = ob_get_clean(); 
$mail_sent = mail($to, $subject, $message, $headers); 
echo $mail_sent ? "OK!!" : "not OK!!";
}
?>

適切に表示するためにphpコードに何かできるかどうか疑問に思います。そうしないと、html形式をあきらめなければならないかもしれません。ありがとうございました。

4

3 に答える 3