联系人形式/消息体中的Php变量

时间:2014-08-18 13:49:26

标签: php forms email contact-form

我有一个联系表单,只是通过一些表单字段,我想知道是否有人可以帮助为什么?

html表格如下:

            <form enctype="multipart/form-data" method="post" action="referral.php" onsubmit="return submitForm()">
      <fieldset>
          <div class="field">
            <input name="name" id="name" type="text" class="validate" placeholder="Your Name" />
            <span class="form-msg" id="name-error">Please add your name</span>
          </div>
            <div class="field here-for-next-until">
              <input name="email" id="email" type="text" class="validate" placeholder="Your E-mail" class="text-input validate" />
              <span class="form-msg" id="email-error">Please add your e-mail address</span>
            </div>
            <div class="field">
              <input name="phone" id="phone" type="text" placeholder="Your Phone Number" class="text-input validate" />
              <span id="phone-error" class="form-msg" >Please add your phone number</span>
            </div>                        
            <div class="area here-for-next-until">
              <textarea name="message" id="message" class="text-input validate" placeholder="Introduce Yourself"></textarea><br/>
              <span class="form-msg" id="email-error">Please add an introduction to yourself</span>
              <input type="text" id="cap_val" name="cap_val" class="code validate" placeholder="Enter Code From Right"/>
              <img src="bin/captcha.php" id="cap"/><img src="images/refresh.jpg" id="cap-refresh" onclick="change_captcha()"/><br/>
            <span id="captcha-error" class="form-msg" >Please add the above code</span>
            <div class="clear here-for-next-until"></div>
          </div>
    </div>

   <div class="flt-lt w420">
    <h2 class="subheader">Client</h2>
          <div class="field">
            <input name="referralsname" id="name" type="text" class="validate" placeholder="Name" />
            <span class="form-msg" id="name-error">Please add your referrals name</span>
          </div>
            <div class="field here-for-next-until">
              <input name="referralsemail" id="email" type="text" class="validate" placeholder="E-mail address" class="text-input validate" />
              <span class="form-msg" id="email-error">Please add your referrals e-mail address</span>
            </div>
            <div class="field">
              <input name="referralsphone" id="phone" type="text" placeholder="Phone Number" class="text-input validate" />
              <span id="phone-error" class="form-msg" >Please add your referrals phone number</span>
            </div>                        
            <div class="area here-for-next-until">
              <textarea name="referralsmessage" id="message" class="text-input validate" placeholder="Introduce Yourself"></textarea><br/>
              <span class="form-msg" id="email-error">Please add an introduction to yourself</span>
            <div class="clear here-for-next-until"></div>
                        <div id="submit-holder">
              <input class="submit" type="submit" value="Submit"/>
              <input id="reset" class="submit" type="reset" value="Reset"/>
            </div>
          </div>
      </fieldset>
    </form>

基本上这是两个非常相似的联系表格,它们共享一个提交按钮

发布时,请转到:

$owner_email = 'myemail.co.uk';
  $subject = A message from your site visitor ' . $_POST["name"];

  $messageBody = "\nVisitor: " . $_POST["name"] . "\n";
  $messageBody .= "Email Address: " . $_POST['email'] . "\n";
  $messageBody .= "Phone Number: " . $_POST['phone'] . "\n";
  $messageBody .= "Message: " . $_POST['message'] . "\n";

  $messageBody = "\nVisitor: " . $_POST["referralsname"] . "\n";
  $messageBody .= "Email Address: " . $_POST['referralsemail'] . "\n";
  $messageBody .= "Phone Number: " . $_POST['referralsphone'] . "\n";
  $messageBody .= "Message: " . $_POST['referralsmessage'] . "\n";

然而,当我提交表单时,我将获得一组详细信息(第一个4 $ messageBody)

任何人都可以提供的帮助将不胜感激。

再次感谢

大卫

2 个答案:

答案 0 :(得分:1)

变化:

$messageBody = "\nVisitor: " . $_POST["referralsname"] . "\n";

要:

$messageBody .= "\nVisitor: " . $_POST["referralsname"] . "\n";

。= 而不是 = ,您正在为$ messageBody重新分配值,而不是将其链接到$ messageBody)

答案 1 :(得分:1)

如果我不得不猜测,我会说这是因为你正在重复这些ID。在HTML元素中,ID必须是唯一的。使所有ID与您的&#34;名称相匹配&#34;值。我指的是

<input name="phone" id="phone"....
<input name="referralsphone" id="phone"....

将所有这些案例更改为:

<input name="phone" id="phone"....
<input name="referralsphone" id="referralsphone"....

我还建议检查POST的内容。这个问题显示了Echo an $_POST in PHP

的方式