有什么方法可以将 HTML 代码放入电子邮件和自动回复消息中吗?当我尝试发送电子邮件时,它也使用 HTML 代码输出。
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$mailto = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e0898e868fa097858293899485ce838f8d" rel="noreferrer noopener nofollow">[email protected]</a>';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Email Subject';
$message = 'Hello, Email message...'; // Want to try something like '<Strong>Hello</strong> Email message...'
$success_url = './success.php';
$error_url = './failed.php';
$error = '';
$autoresponder_from = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f09e9f8295809c89b087959283998495de939f9d" rel="noreferrer noopener nofollow">[email protected]</a>';
$autoresponder_subject = 'Auto Response Subject';
$autoresponder_message = 'Hello John, Thank you.'; // Want to try something like '<Strong>Hello John</strong> Thank you.'
最佳答案
您需要为 html 电子邮件设置正确的 header
看看示例#4:http://www.php.net/manual/en/function.mail.php
PHP
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
不要忘记添加消息的纯文本副本
关于php - 在 PHP 电子邮件中使用 HTML 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18613795/