I have a form on a site that allows the user to enter their name, phone, email etc. When I receive this information as an email it comes in completly unformated, so it's a little harder to read. See image below:

我在网站上有一个表单,允许用户输入他们的姓名,电话,电子邮件等。当我收到这些信息作为电子邮件时,它完全没有格式化,所以它有点难以阅读。见下图:

Is there a way I can style this using CSS, ie. make the From and email headings bold {font-weight:bold;}?

有没有办法可以使用CSS来设置它,即。使From和电子邮件标题加粗{font-weight:bold;}?

The php I'm using for the form is:

我用于表单的php是:

<?php
$name        = $_POST['name'];
$email       = $_POST['email'];
$phone       = $_POST['phone'];
$message     = $_POST['message'];
$formcontent ="From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient   = "studio@ll-i.co.uk";
$subject     = "Contact Form";
$mailheader  = "From: $email \r\n";

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

echo "<p>Thanks for getting in touch, we'll get back to you shortly..</p>";
?>

2 个解决方案

#1


3

You have to style it with inline CSS / CSS embedded in the of a HTML file.

您必须使用嵌入在HTML文件中的内联CSS / CSS来设置样式。

The $formcontent variable can contain HTML e.g.

$ formcontent变量可以包含HTML,例如

"<html>
    <head>
        <title>Message</title>
    </head>
    <body>
        <p><strong>From:</strong> $name</p>
        <p><strong>Email:</strong> $email</p>
        <p><strong>Phone:</strong> $phone</p>
        <p><strong>Message:</strong> $message</p>
    </body>
</html>"

Put the CSS in the head of this like so:

把CSS放在这个的头部就像这样:

<head>
   <style type="text/css">
       body { background-color: #ff0000; }
   </style>
</head>

Obviously you'll have to use these: ' instead of these " and concatenate any variables using either a full stop or comma incase you need to use speech quotes for any of the HTML.

显然你必须使用这些:'而不是这些'并使用句号或逗号来连接任何变量,你需要为任何HTML使用语音引号。

Like this:

'<html>
    <head>
        <title>Message</title>
        <style type="text/css">
           body { background-color: #ff0000; }
        </style>
    </head>
    <body>
        <p><strong>From:</strong> ',$name,'</p>
        <p><strong>Email:</strong> ',$email,'</p>
        <p><strong>Phone:</strong> ',$phone,'</p>
        <p><strong>Message:</strong> ',$message,'</p>
    </body>
</html>'

EDIT:

You should also change your headers like so:

您还应该像这样更改标题:

$mailheader = "MIME-Version: 1.0" . "\r\n";
$mailheader .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$mailheader .= "From: $email \r\n";

更多相关文章

  1. 请问如何用php实现表单提交后以邮件的形式把表单内容发到邮箱中
  2. 如何在jQuery Mobile页面中提交表单?
  3. Symfony2 -从数据库中提取数据并以表单形式显示
  4. laravel 框架自带表单验证
  5. 如何检查电子邮件id是否存在?
  6. AJAX学习之提交表单
  7. 在提交注册表单时使用jQuery显示错误
  8. 如果改变输入值,jQuery提交表单
  9. 如何在表单操作中执行PHP函数?

随机推荐

  1. 如何在php中找到更轻或更暗版本的十六进
  2. 从浏览器中删除发送到服务器的标题。
  3. 是否可以在ajax中使用动态变量?
  4. PHP DOMNode:如何不仅提取文本,而且提取HT
  5. dedecms lnmp 环境搭建。备忘录非教程
  6. thinkphp友情链接代码
  7. thinkphp整合系列之tcpdf类生成pdf文件
  8. php中global的作用
  9. 要求PIN使用Symfony2登录
  10. PHP中是否存在“clamp”数字函数?