【问题标题】:Bootstrap Contact Form - How to send html emailBootstrap 联系表 - 如何发送 html 电子邮件
【发布时间】:2015-03-20 01:37:21
【问题描述】:

我正在使用bootstrap contact form. 表单工作正常,但无论我做什么我都无法让它发送 html 电子邮件。我在脚本的不同部分添加了内联的标题和 css,但它从不发送带有任何 html 格式的电子邮件。我把头撞在墙上,非常感谢任何帮助。我应该把 headers 变量放在哪里,把 html 放在哪里?

这是php代码。

<?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。

<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>

【问题讨论】:

  • 脚本在尝试发送邮件后是否呈现“成功”或“错误”条件?

标签: php css twitter-bootstrap


【解决方案1】:

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

【讨论】:

  • 太棒了。做到了。非常感谢。
猜你喜欢
  • 2011-05-30
  • 2018-04-15
  • 2020-05-20
  • 2019-10-03
  • 2020-12-07
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多