0

我有一个非常简单的联系表格(或者我是这么想的),但是 9 个联系字段中只有 2 个被发送到我的收件箱。奇怪的是,它是列表中的最后两个字段,尽管“发件人”电子邮件地址和主题工作正常。

 <form id="quote" class="contact_form" action="contact.php" method="post">
  <h2>Easy Contact Form</h2>
  <h4>Personal</h4>

    <label for="title">Title:</label>
    <input type="text" name="title" id="title" required class="required" >

    <label for="name">Full Name:</label>
     <input type="text" name="fullname" id="fullname" required class="required" >


    <label for="email">Email:</label>
     <input type="email" name="email" id="email" required placeholder="jsmith@email.com" class="required email">

    <label>Phone:</label>
    <input type="text" name="phone" id="phone" />

  <h4>Address</h4>

    <label>House #:</label>
    <input type="text" name="house" id="house" />

    <label>Street:</label>
    <input type="text" name="street" id="street" />

   <label>Town/City:</label>
    <input type="text" name="town" id="town" />

    <label>Postcode:</label>
    <input type="text" name="postcode" id="postcode" />

  <h4>Lender</h4>

    <label>Company Name:</label>
    <input type="text" name="companyname" id="companyname" />

  <input class="btn" type="image" src="images/submit_btn.jpg"/>
</form>

这是PHP:

<?php

$EmailFrom = $_REQUEST['email']; 
$EmailTo = "me@email.com";
$Subject = "Information";
$Title = Trim(stripslashes($_POST['title'])); 
$Fullname = Trim(stripslashes($_POST['fullname'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Message = Trim(stripslashes($_POST['phone']));
$House = Trim(stripslashes($_POST['house'])); 
$Street = Trim(stripslashes($_POST['street'])); 
$Town = Trim(stripslashes($_POST['town'])); 
$Postcode = Trim(stripslashes($_POST['postcode'])); 
$Companyname = Trim(stripslashes($_POST['companyname'])); 


// validation
$validationOK=true;
if (!$validationOK) {
echo "Error";
exit;
}

// prepare email body text
$Body = "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "Fullname: ";
$Body .= $Fullname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body = "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body = "house: ";
$Body .= $house;
$Body .= "\n";
$Body = "Street: ";
$Body .= $Street;
$Body .= "\n";
$Body = "Town: ";
$Body .= $Town;
$Body .= "\n";
$Body = "Postcode: ";
$Body .= $Postcode;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $Companyname;

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

// redirect to success page 
if ($success){
echo "Succes";
}
else{
echo "Error";
}
?>
4

2 回答 2

1

这是问题所在:

// prepare email body text
$Body = "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "Fullname: ";
$Body .= $Fullname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body = "Phone: "; //needs dot
$Body .= $Phone;
$Body .= "\n";
$Body = "house: ";
$Body .= $house;
$Body .= "\n";
$Body = "Street: "; //needs dot
$Body .= $Street;
$Body .= "\n";
$Body = "Town: "; //needs dot
$Body .= $Town;
$Body .= "\n";
$Body = "Postcode: "; //needs dot
$Body .= $Postcode;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $Companyname;

您需要确保每一行都有.=而不是只有=. 在您拥有的底部附近$Body = "Postcode: ";,您正在重置整个 $Body 变量。

于 2013-10-20T16:12:43.977 回答
0

问题来自$body.

// prepare email body text
$Body = "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "Fullname: ";
$Body .= $Fullname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body = "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body = "house: ";
$Body .= $house;
$Body .= "\n";
$Body = "Street: ";
$Body .= $Street;
$Body .= "\n";
$Body = "Town: ";
$Body .= $Town;
$Body .= "\n";
$Body = "Postcode: ";
$Body .= $Postcode;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $Companyname;

第一个变量声明$Body = "Title: ";很好,但是之后您需要确保使用.=.

每次在您使用的初始声明之后=,它都会清除之前分配或附加的所有内容并重新开始。

这就是为什么您只看到最后 2 个表单字段的原因,因为$Body = "Postcode: ";重新启动变量,删除之前的所有内容。

用于.=除第一行之外的每一行,第一行应该是=.

希望这可以帮助!

于 2013-10-20T16:20:20.687 回答