HTML / PHP表单发送带有空白字段的电子邮件

时间:2022-10-23 19:14:32

I have written a contact form in Dreamweaver and embedded it in Adobe Muse. Problem is that the form sends an email OK, but with blank fields, just the headings. It's probably a problem with my code, as I'm a relative noob with HTML and even more so with PHP. The PHP script was originally downloaded from 123reg, as that is where the website is hosted. Obvs I've tweaked it to suit. I've looked at other posts with similar problems but nothing has worked.` The form seems to work ok, so maybe I can start with the PHP.

我在Dreamweaver中编写了一个联系表单并将其嵌入Adobe Muse中。问题是表单发送电子邮件确定,但是有空白字段,只是标题。这可能是我的代码的问题,因为我是HTML的相对noob,甚至更多的PHP。 PHP脚本最初是从123reg下载的,因为这是托管网站的地方。 Obvs我已经调整它以适应。我看过其他有类似问题的帖子,但没有任何效果。表单似乎工作正常,所以也许我可以从PHP开始。

    <?php

$EmailFrom = "sales@trisomet.com";
$EmailTo = "sales@hairwraps.co.uk";
$Subject = "QuikQuote Web Enquiry";
$name = trim(stripslashes($_POST['Name']));
$email = trim(stripslashes($_POST['Email']));
$tel = trim(stripslashes($_POST['Tel']));
$textfield2 = trim(stripslashes($_POST['Postcode']));
$textarea = trim(stripslashes($_POST['Message']));
$RoofType = trim(stripslashes($_POST['Roof Type']));
$number = trim(stripslashes($_POST['Roof Length']));
$number2 = trim(stripslashes($_POST['Roof Width']));
$RadioGroup1 = trim(stripslashes($_POST['Fixings']));
$Flashing = Trim(stripslashes($_POST['Flashings']));
$panels = trim(stripslashes($_POST['Clear Panels']));
$number3 = trim(stripslashes($_POST['Quantity']));
$number4 = trim(stripslashes($_POST['Length']));

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $tel;
$Body .= "\n";
$Body .= "Postcode: ";
$Body .= $textfield2;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $textarea;
$Body .= "\n";
$Body .= "Roof Type: ";
$Body .= $RoofType;
$Body .= "\n";
$Body .= "Roof Length: ";
$Body .= $number;
$Body .= "\n";
$Body .= "Roof Width: ";
$Body .= $number2;
$Body .= "\n";
$Body .= "Fixings: ";
$Body .= $RadioGroup1;
$Body .= "\n";
$Body .= "Flashing: ";
$Body .= $Flashing;
$Body .= "\n";
$Body .= "Clear Panels: ";
$Body .= $panels;
$Body .= "\n";
$Body .= "Quantity: ";
$Body .= $number3;
$Body .= "\n";
$Body .= "Length (m): ";
$Body .= $number4;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"1;URL=index.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"1;URL=error.html\">";
}
?>

Does anything look obviously wrong? I think my HTML declaration is ok -

看起来有什么不对吗?我认为我的HTML声明没问题 -

 <form action="contactform.php" method="post" class="form">

Any help would be fantastic as it's doing my nut in!!

任何帮助都会很棒,因为它正在做我的坚果!!

here's the html

这是html

 <div id="formWrapper">
  <form action="contactform.php" method="post" class="form">
  <div class="container" style="width: 100%; ">
    <div class="sidebar" style="width: 365px; height:255px; margin-left:10px; float: left; ">
        <label for="textfield"><strong>Name</strong>:</label>
    <input name="textfield" type="text" required id="textfield" size="40">
  </p><br>
  <p>
    <label for="email"><strong>Email:</strong></label>
    <input name="email" type="email" required id="email" size="40">
  </p><br>
  <p>
    <label for="tel"><strong>Telephone: </strong></label>
        <input name="tel" type="tel" required id="tel" size="40">
          </p><br><p>
  <label for="textfield2"><strong>Postcode:</strong></label>
  <input name="textfield2" type="text" required id="textfield2">
          </p>
    </div>
    <div class="content" style="width:365px; height: 255px; float:right; margin-right:10px;">
         <label for="textarea"><strong>Message:</strong></label>
    <strong>
    <textarea name="textarea" rows="13" cols="40"></textarea>
    </strong></p>
    </div>

  </div>
  <div class="content3" style="width: 220px; height:110px; margin-left:10px; float: left;">
        <label for="Roof Type"><strong>Roof Type: </label>
      </strong>

      <label>
        <input name="Roof Type" type="radio" required id="RoofType_0" title="Roof Type" value="Single Slope">
        Single Slope</label>
      <label>
        <input type="radio" name="Roof Type" value="Symmetrical Apex" id="RoofType_1">
        Symmetrical Apex</label>
      <label>
        <input type="radio" name="Roof Type" value="Asymmetrical Apex" id="RoofType_2">
        Asymmetrical Apex</label>

  </div>
  <div class="content4" style="width: 215px; height: 110px; float:left; ">
  <label for="number"><strong>Roof Length (m):</strong></label>
    <input name="number" type="number" required id="number">
    <label for="number2"><strong>Roof Width (m):</strong></label>
    <input name="number2" type="number" required id="number2">
  </div>
  <div class="content5" style="width:210px; height: 110px; float:left; ">
  <label><strong>Fixings:</strong><br>

      <input name="RadioGroup1" type="radio" required id="RadioGroup1_0" value="Timber">
Timber</label>

    <label>
      <input type="radio" name="RadioGroup1" value="Light Section Steel" id="RadioGroup1_1">
      Light Section Steel</label>

    <label>
      <input type="radio" name="RadioGroup1" value="Heavy Section Steel" id="RadioGroup1_2">
      Heavy Section Steel</label>
  </div>
  <div class="content6" style="width:85px; height: 110px;float:left; ">
  <strong>Flashing:
</strong>
    <label>
      <input name="Flashing" type="radio" required id="Flashing_0" value="Yes">
      Yes</label>
    <label>
      <input type="radio" name="Flashing" value="No" id="Flashing_1">
    No</label>

  </div>
  <div class="content7" style="width:150px; margin-left: 10px; height: 90px; float:left; ">
  <label for "panels" style="font-weight:bold">Clear Panels:</strong></label>
    <label>
      <input name="panels" type="radio" required id="panels_0" value="Yes">
      Yes</label>
    <label>
      <input type="radio" name="panels" value="No" id="panels_1">
      No</label>

  </div>

  <div class="content8" style="width:100px; height: 110px; float:left;">
<label for="number3"><strong>Quantity:</strong></label>
  <input name="number3" type="number" required id="number3" style="width:80px" value="0">
  </div>
  <div class="content9" style="width:150px; height:110px;float:left;">
  <label for="number4"><strong>Length (m):</label>
  <input name="number4" type="number" required id="number4" style="width:80px" value="0">
  </div>
 <div class="submitb" style="width:190px; height:110px; float:left; ">
 <p>
 <input type="submit" name="submit" id="submit" value="Get A Quote >">
 </p>
 </div>


</form></div>

1 个解决方案

#1


0  

I seem to have solved my own problem. I thought the top $POST fields were the field headings for the emails, whereas they are actually the field names from my form. DUH!!!!!

我好像已经解决了自己的问题。我认为最好的$ POST字段是电子邮件的字段标题,而它们实际上是我表单中的字段名称。杜!!!!!

#1


0  

I seem to have solved my own problem. I thought the top $POST fields were the field headings for the emails, whereas they are actually the field names from my form. DUH!!!!!

我好像已经解决了自己的问题。我认为最好的$ POST字段是电子邮件的字段标题,而它们实际上是我表单中的字段名称。杜!!!!!