php邮件:如何发送html? [英] Php mail: how to send html?

查看:110
本文介绍了php邮件:如何发送html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是正确发送电子邮件,但是正文。我需要在消息的正文中显示html,我无法做到。网络中的示例不会发送电子邮件:(

The code below is sending an email correctly but for the body. I need to show html in the body of the message and I cannot make it. The examples in the web won't send the email :(

如何修复我的代码发送电子邮件与身体的HTML?

How can I fix my code to send the email with the html in the body?

感谢一下!

<?php

$to = 'mymail@mail.com';

$subject = 'I need to show html'; 

$from ='example@example.com'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
  $headers .= "Content-type: text/html\r\n"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

?>


推荐答案

使用此标题的邮件: / p>

use this header for the mail:

 $header  = "MIME-Version: 1.0\r\n";
 $header .= "Content-type: text/html; charset: utf8\r\n";

和内容/正文:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
... ... ...

使用内联css命令和建议使用表格进行界面。

it's important to use inline css commands and recommanded to use tables for the interface.

...

在你的Mail-Body你不必把 HTML代码与头和身体

In your Mail-Body you than have to put HTML code with head and body

这篇关于php邮件:如何发送html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆