【问题标题】:Bootstrap email form not working properly. Is it my html or php?引导电子邮件表单无法正常工作。是我的html还是php?
【发布时间】:2015-06-20 21:38:53
【问题描述】:

我的电子邮件表单的 php 或 html 有什么问题吗?每次我在线提交表格时,我都会得到一个空白页。我不确定我还需要改变什么,因为这似乎很有意义,但我对 php 了解不多。

<form class="form-vertical" role="form" method="post" action="index.php">
    <fieldset>

    <!-- Text input-->
    <div class="form-group">
       <label class="control-label" for="textinput">Name</label>  
       <input id="textinput" name="textinput" type="text" placeholder="Enter Name" class="form-control input-md">
    </div>

    <!-- Text input-->
    <div class="form-group">
       <label class="control-label" for="Email">Email</label>  
       <input id="Email" name="Email" type="text" placeholder="Enter Email" class="form-control input-md">
    </div>

    <!-- Text input-->
    <div class="form-group">
        <label class="control-label" for="Phone">Phone</label>  
        <input id="Phone" name="Phone" type="text" placeholder="" class="form-control input-md">
    </div>
</section>
</div> <!-- end col-md-4 -->

<div class="col-md-4 message-form">
    <section class="wow zoomInUp" data-wow-duration="1.5s" data-wow-delay="0.2s" style="visibility: visible; -webkit-animation-delay: 0.2s; -moz-animation-delay: 0.2s; animation-delay: 0.2s;">
        <!-- Textarea -->
        <div class="form-group">
            <label class="control-label" for="Message">Message</label>

            <textarea class="form-control" rows="5" id="Message" name="Message" placeholder="Message"></textarea>
        </div>

        <!-- Button -->
        <div class="form-group">
            <label class="control-label" for="Submit"></label>
            <button id="Submit" name="Submit" class="btn btn-primary pull-right">Send Message</button>
        </div>
    </fieldset>
</form>

PHP 脚本

<?php
if ($_POST["Submit"]) {
    $textinput = $_POST['textinput'];
    $Email = $_POST['Email'];
    $Phone = $_POST['Phone'];
    $Message = $_POST['Message'];
    $from = 'Demo Contact Form'; 
    $to = 'max.henry.campos@gmail.com'; 
    $subject = 'Message from Contact Demo ';

    $body = "From: $textinput\n E-Mail: $Email\n Message:\n $Message";

    // Check if name has been entered
    if (!$_POST['textinput']) {
        $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 message has been entered
    if (!$_POST['Message']) {
        $errMessage = 'Please enter your message';
    }

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

【问题讨论】:

  • 您的页面顶部是否有ini_set('display_errors',1); error_reporting(E_ALL); 来捕获错误?
  • 你当前的文件名是什么?
  • 我将它添加到顶部,但它什么也没做。我确定我做错了什么。我所有与我的表单相关的代码都已发布。我只需要知道缺少什么以及我应该把它放在哪里。

标签: php html forms twitter-bootstrap email


【解决方案1】:

好吧,您可能会得到空白页,因为您实际上并没有向浏览器返回任何内容。你只是在设置 $result,而不是输出它。

if (mail ($to, $subject, $body, $from)) {
    $result='<div class="alert alert-success">Thank You! We will be in touch</div>';
} else {
    $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}

回显 $result; // ?

【讨论】:

  • 回显 $result; // ?那是假设去某个地方吗?我只需要知道缺少什么以及我应该把它放在哪里。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2011-09-07
  • 1970-01-01
  • 2018-10-03
  • 2012-07-12
  • 2011-02-25
相关资源
最近更新 更多