电子邮件包括样式代码,带联系表格的模态窗口,使用php

时间:2016-09-13 18:10:39

标签: php bootstrap-modal contact-form

我使用bootstrap在模态窗口中创建了一个联系表单。表单的操作等于我的php文件,它将消息放在一起并发送。电子邮件按原样发送,但在电子邮件的消息块中,它包含一些我没有使用的样式代码,因此它必须来自引导程序。我会在这里发布代码。我已经回复了帖子和其他变量的print_r,并且无法对该输出中的样式代码进行细化。我使用ScotchBox作为我的盒子和它的邮件收发器来检查电子邮件状态。

<!-- trigger modal -->
   <button id="contact-button" data-toggle="modal" data-target="#contactModal">Contact</button>

    <!-- Modal -->
    <div class="modal fade" id="contactModal" role="dialog">
        <div class="modal-dialog">

            <!-- modal content -->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h1 class="modal-title" id="contact-title">Contact Us</h1>
                </div>
                <div class="modal-body">
                    <div class="main_form">
                        <form method="post" action="send_email.php">
                            <input id="text-block" type="text" name="full_name" placeholder=" Full Name" required>
                            <input id="text-block" type="text" name="email" placeholder=" Email" required>
                            <input id="text-block" type="text" name="telephone" placeholder=" Telephone" required>
                            <br>
                            <input id="sub-button" name="submit" type="submit" value="Submit">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

这是我的send_email.php文件

<?php
session_start();

if (isset($_POST['submit'])) {
    $to = "someemail@email.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $full_name = $_POST['full_name'];
    $email = $_POST['email'];
    $telephone = $_POST['telephone'];
    $subject = "Contact Request";
    $message_before =  "Full Name:  " . $full_name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $telephone;
    $message = strstr($message_before, "Full Name");

    mail($to, $subject, $message);

    header('Location: contact.php');
}?>

我在邮件收发器中收到的电子邮件在应该存在的文本前面。

html.cye-enabled.cye-nm:not(*:-webkit-full-screen) body,
html.cye-enabled.cye-nm:not(*:-webkit-full-screen) #cye-workaround-body {
  -webkit-filter: contrast(48%) brightness(124%) invert(1);
}

html.cye-enabled.cye-lm body {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm div {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm th {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm td {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm input[type=text] {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm textarea {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm select {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm ul {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

html.cye-enabled.cye-lm .cye-lm-tag,html.cye-enabled.cye-lm.cye-lm-tag {
  background-color: #000000 !important;
  border-color: rgb(2, 1, 2) !important;
  background-image: none !important;
  color: #FFFFFF !important;
}

2 个答案:

答案 0 :(得分:0)

Bootstrap与jquery / javascript一起使用,不应该用于HTML电子邮件,因为几乎所有的电子邮件客户端都会从邮件中删除javascript。使用内联css或样式块添加样式。还有一个用于开发HTML电子邮件的框架:

http://foundation.zurb.com/emails.html

答案 1 :(得分:0)

网站已部署到服务器,现已上线。电子邮件在实时环境中不包含所有样式代码。 Scotch-box和虚拟环境一定存在问题。

我遇到了一些其他问题,我将编辑并提供给Scotch-box上的人,以便他们知道存在一些问题。