php - 在 PHP 电子邮件中使用 HTML 代码

标签 php html email

有什么方法可以将 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/

相关文章:

php - Magento - 仅在 url 中显示当前类别

javascript - 页面加载后加载ajax

email - PowerShell 邮件编码

php - 单选按钮未显示在页面中

php - paypal express - 结帐客人

php - 如何直接从 Eclipse 环境为 Eclipse 安装 PHP IDE 插件?

php - PHP 中的 mail() 函数带有奇怪的字符

javascript - 如何使 3D 对象跟随网页中的光标?

html - 子元素不应该反倾斜

c# - 无法使用 Gmail/Yahoo 等外发邮件服务器使用端口 465 在 C# 中发送邮件