联系表单仅发送某些字段

时间:2014-10-23 21:55:03

标签: php html forms input

我有一个只发送某些特定字段的联系表单,我不完全确定原因。公司名称和位置正在发送,但描述不是。这是下面的脚本。

PHP方面:

$companyname=$_REQUEST['companyname'];
$location=$_REQUEST['location']; 
$description=$_REQUEST['description']; 
if (($companyname=="")||($location=="")||($description=="")) 
    { 
    echo "Company Name, Company Location, and Company Description are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: <$email>\r\nReturn-path: $email"; 
    $subject="Company Information"; 
    mail("n.dumanov@gmail.com", $subject, $companyname, $location, $description); 

    } 
}   

HTML表单:

  <form class="xform" id="admin_form" method="post">
  <label align = "left">Company Name *</label>
  <section class="col col-4">
    <label class="input"> <i class="icon-prepend icon-user"></i> <i class="icon-append icon-asterisk"></i>
      <input type="text" name="companyname" placeholder="Company Name">
    </label>
  </section><br>
       <label align = "left">Company's Province of Operation *</label>
  <section class="col col-4">
    <label class="input"> <i class="icon-prepend icon-user"></i> <i class="icon-append icon-asterisk"></i>
      <input type="text" name="location" placeholder="Company's Province of Operation">
    </label>
  </section><br>
       <label align = "left">Company Description *</label>
  <section class="col col-4">
    <label class="input"> <i class="icon-prepend icon-user"></i> <i class="icon-append icon-asterisk"></i>
                <textarea type="text" name="description" placeholder="Please be as specific as possible. Include information about what kind of work your company does, what sector you operate in, and the type of legal services you will require."></textarea>
    </label>
  </section><br><form>

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:3)

使用$ _POST获取表单数据是可接受的方法,但这不是问题。您必须将mail()函数传递给消息的第三个参数。

这就是mail()的工作原理:

bool mail (string $to, string $subject, string $message [,string $additional_headers [,string $additional_parameters ] ] )

因此,如果您想将表单数据作为邮件正文发送,则必须执行以下操作:

$message = $companyname." ";
$message .= $location. " ";
$message .= $description;
mail("the@mail.com",$subject,$message);

消息之外的参数是可选的,如果你按照它设置它们,你就告诉mail()$ location是一个带有额外标题和$ description其他可选参数的字符串。

阅读文档以获取有关标题和额外参数实际含义的更多信息:

http://php.net/manual/en/function.mail.php

答案 1 :(得分:-3)

不要使用$ _REQUEST,而是尝试在第1,2和3行使用$ _POST替换PHP。