【问题标题】:Using HTML code in PHP email [duplicate]在 PHP 电子邮件中使用 HTML 代码 [重复]
【发布时间】:2013-09-04 12:26:15
【问题描述】:

有什么方法可以将 HTML 代码放入电子邮件消息和自动回复消息中?当我尝试使用 HTML 代码输出电子邮件时。

   if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  $mailto = 'info@website.com';
  $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 = 'noreply@website.com';
  $autoresponder_subject = 'Auto Response Subject';
  $autoresponder_message = 'Hello John, Thank you.'; // Want to try something like '<Strong>Hello John</strong> Thank you.'

【问题讨论】:

  • 是的,只需为 HTML 使用正确的标题。 $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";Consult the PHP manual
  • 不要发送没有纯文本替代的 HTML 格式的电子邮件。本世纪不要使用 ISO-8855。
  • PHP 的内置 mail() 函数对于 HTML 电子邮件等复杂的东西来说很糟糕。考虑使用一个不错的邮件类,例如 PHPMailer,它会让你的事情变得简单。

标签: php html email


【解决方案1】:

您需要为 html 电子邮件设置正确的标题

查看示例 #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";

不要忘记添加您的消息的纯副本

【讨论】:

  • “不要忘记添加您的消息的纯副本” - 您要做的第一件事就是不要$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  • @Quentin 今天我学到了更多东西; “注明并归档”。
猜你喜欢
  • 2020-09-27
  • 2011-10-15
  • 2013-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多