0

从我的“联系我们”页面发送的电子邮件仅包含主题“联系我们页面消息来自”和正文消息的第一部分,例如来自:IGN:电子邮件:

似乎这些字段不起作用,但我不知道为什么。

这是我联系我们的 php 代码:

$mail_to = 'support@mineyc.com';
$subject = 'Contact Us page message from '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'IGN: '.$field_ign."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = '/contactus.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to support@mineyc.com');
        window.location = '/contactus.html';
    </script>
<?php
}
?>

这是HTML代码:

    <!-- Main Content -->
    <div class="container">
      <div class="well">
        <div class="row">
          <div class="col-lg-6">
            <div class="well">
              <form class="form-horizontal" action="/php/contact.php" method="post">
                <fieldset>
                  <legend>Contact Us</legend>
                  <div class="form-group">
                    <label for="inputName" class="col-lg-2 control-label">Name</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" id="inputName" placeholder="Name">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputIGN" class="col-lg-2 control-label">IGN</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" id="inputIGN" placeholder="In-game Name">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputEmail" class="col-lg-2 control-label">Email</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" id="inputEmail" placeholder="Email">
                    </div>
                  </div>
                  <div class="form-group">
                        <label for="textArea" class="col-lg-2 control-label">Message</label>
                    <div class="col-lg-10">
                          <textarea class="form-control" rows="3" id="textArea"></textarea>
                      <span class="help-block">Please enter a real email address so that we can reply to your message.</span>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
                      <button type="submit" class="btn btn-primary">Submit</button> 
                    </div>
                  </div>
                </fieldset>
              </form>
            </div>
          </div>
        </div>
    </div>

一定是某个地方出现了一些小错误,或者我在 HTML 中遗漏了一些东西。提前感谢您的帮助。

4

2 回答 2

0

您的字段没有任何name属性。提交表单时,未命名的字段不会传递给 PHP 脚本。Yopur 输入需要这样的name属性:

<input type="text" class="form-control" id="inputIGN" name="inputIGN" placeholder="In-game Name">

可以使用相同的id并且name

您的 PHP 脚本似乎没有尝试读取任何传递的变量,因此不清楚您希望表单数据如何到达电子邮件。

要阅读我上面说明的输入,您可以使用:

$field_ign = $_POST['inputIGN'];

您需要为您的所有<input><textarea>

于 2013-09-29T22:35:02.823 回答
0

您的表单输入没有任何名称。在表单中命名每个输入以发布数据

<div class="container">
      <div class="well">
        <div class="row">
          <div class="col-lg-6">
            <div class="well">
              <form class="form-horizontal" action="" method="post">

                  <legend>Contact Us</legend>
                  <div class="form-group">
                    <label for="inputName" class="col-lg-2 control-label">Name</label>
                    <div class="col-lg-10">
                      <input type="text"  name="inputName" class="form-control" id="inputName" placeholder="Name">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputIGN"  class="col-lg-2 control-label">IGN</label>
                    <div class="col-lg-10">
                        <input type="text" name="inputIGN" class="form-control" id="inputIGN" placeholder="In-game Name">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputEmail" class="col-lg-2 control-label">Email</label>
                    <div class="col-lg-10">
                        <input type="text"  name="inputEmail" class="form-control" id="inputEmail" placeholder="Email">
                    </div>
                  </div>
                  <div class="form-group">
                        <label for="textArea" class="col-lg-2 control-label">Message</label>
                    <div class="col-lg-10">
                          <textarea class="form-control" rows="3" id="textArea"></textarea>
                      <span class="help-block">Please enter a real email address so that we can reply to your message.</span>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
                        <input type="submit" value="Save" name="submit"/>
                    </div>
                  </div>

              </form>
            </div>
          </div>
        </div>
    </div>
于 2013-09-29T22:35:23.963 回答