繁体   English   中英

PHP mail(); 以纯文本和HTML格式发送电子邮件

[英]PHP mail(); Send e-mail as plain text AND a HTML

我有以下PHP代码用于发送带有PHP mail()的电子邮件作为HTML

<?php
    $to = "test@example.com";

    $subject = "This is the subject";

    $headers = "From: Me<test@exapmle.com>\r\n";
    $headers .= "Return-Path: test@exapmle.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $headers .= "X-Priority: 1\r\n";

    $message = "This is my <b>message</b>!";

    mail($to,$subject,$message,$headers);
?>

但我想支持纯文本和HTML。 用于显示粗体字体和纯文本等内容的HTML This is my message! 在非HTML支持电子邮件客户端而不是This is my <b>message</b>!

我怎样才能做到这一点?

我读到了边界。 这就是我要找的东西吗? 但如果是这样,如何使用它? 我不明白。

我强烈建议你使用像PHPMailer( https://github.com/PHPMailer/PHPMailer )这样的现有库,它可以做你需要的一切甚至更多。

$mail = new PHPMailer;
$mail->isHTML(true);
$mail->Body = '<b>Html body</b> here.';
$mail->AltBody = 'Normal text here.';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM