首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >引导联系人表单-如何发送html电子邮件

引导联系人表单-如何发送html电子邮件
EN

Stack Overflow用户
提问于 2015-03-19 17:33:19
回答 1查看 1.3K关注 0票数 1

我使用的是一个自举接触形式。,该表单工作良好,但无论我做什么,我都无法让它发送html电子邮件。我增加了标题和css内联到脚本的不同部分,但它从来没有发送任何html格式的电子邮件。我把头撞在墙上,希望能得到任何帮助。我应该将headers变量放在哪里,将html放在哪里?

下面是php代码。

代码语言:javascript
复制
<?php
    if ($_POST["submit"]) {
        $name = $_POST['name'];
        $email = $_POST['email'];
                $message = $_POST['message'];
        $human = intval($_POST['human']);
        $from = 'Mywebsite'; 
        $to = 'me@email.com'; 
        $subject = 'Contact Email ';
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "To: ". $to. "\r\n";
$headers .= "From: ". $from;


         $body = " $headers, From: $name\n E-Mail: $email\n Message: $message";


        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }

        //Check if content has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }
        //Check if simple anti-bot test is correct
        if ($human !== 5) {
            $errHuman = 'Your anti-spam is incorrect';
        }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! </div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
    }
}
    }
?>

这是HTML。

代码语言:javascript
复制
<div style="padding:10px; background:#000; font-size:46px; font-weight: 900; color:#fff; ">
        My Website
      </div>
      <div style="padding:24px; font-size:17px; background:#DCDCDC  ; ">
        This is a message from My website.
        <br>

        <br>
        <br>
        <a href="http://www.mywebsite.com">Login in to your account</a>
        <br>
        <br>
      </div>
      <br>
      <br>
    </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-19 17:37:21

mail($to, $subject, $body, $from);替换为mail($to, $subject, $body, $headers);

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29151323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档