dousong5492 2013-10-20 16:05 采纳率: 100%
浏览 88

9个PHP表单字段中只有2个被发送到电子邮件

I've got a pretty simple contact form (or so I thought), but only 2 out of 9 contact fields are being delivered to my inbox. Strangely enough, it's the last two fields in the list, although the 'from' email address, and subject matter are working fine.

 <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>

And here's the 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 .= "
";
$Body .= "Fullname: ";
$Body .= $Fullname;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body = "Phone: ";
$Body .= $Phone;
$Body .= "
";
$Body = "house: ";
$Body .= $house;
$Body .= "
";
$Body = "Street: ";
$Body .= $Street;
$Body .= "
";
$Body = "Town: ";
$Body .= $Town;
$Body .= "
";
$Body = "Postcode: ";
$Body .= $Postcode;
$Body .= "
";
$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";
}
?>
  • 写回答

2条回答 默认 最新

  • dtds8802 2013-10-20 16:12
    关注

    Here's the problem:

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

    You need to make sure each line has .= instead of just =. Near the bottom where you have $Body = "Postcode: ";, you're resetting the entire $Body variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法