通过电子邮件发送联系表格信息

时间:2014-04-01 20:03:05

标签: php forms email

当客户填写我的电子邮件时,会通过电子邮件将其发送到我的电子邮件地址。该电子邮件包含表格中的所有信息,但联系人听到的网站除外。在表单中,此选项是一个下拉菜单。任何建议都会很棒。

这是表格:     

<div class="Row">
<div class="Lable">Full Name:</div> <!--End of Lable-->
<div class="input">
<input type="text" id="fullname" class="detail" name="fullname" placeholder="Full Name" />
</div> <!--End input-->
</div> <!--End row-->


<br />
<div class="Row">
<div class="Lable">Email Address:</div> <!--End of Lable-->
<div class="input">
<input type="text" id="emailaddress" class="detail" name="emailaddress" placeholder="Email Address" />
</div> <!--End input-->
</div> <!--End row-->

    <br />
<div class="Row">
<div class="Lable">Your Message:</div> <!--End of Lable-->
<div class="input">
<textarea id="comment" name="comment" class="mess" placeholder="Your Message"></textarea>
</div> <!--End input-->
</div> <!--End row--> 

<br />
<div class="Row">
<div class="Lable">Select your gender:</div> <!--End of Lable-->
<div class="input">   
<input type="radio" name="gender" value="male"  id="gender_male" CHECKED/>
<label for="gender_male"/>Male
<input type="radio" name="gender" value="female" id="gender_female" />
<label for="gender_female" />Female
</div> <!--End input-->
</div> <!--End row--> 




<br />
<div class="Row">
<div class="Lable">Please select your age:</div>
  <!--End of Lable-->
  <input type="radio" name="age" id="range1" value="18-25" CHECKED />
  18-25 
  <input type="radio" name="age" id="range2" value="26-33" />26-33 
  <input type="radio" name="age" id="range3" value="24-40" />34-40 
  <input type="radio" name="age" id="range4" value="40+" />40+<br />
 </div><!--Row-->

  <br />
  <div class="Row">
<div class="Lable">Select 3 products that you are interested in hearing about:</div> 
<!--End of Lable-->
<input type="checkbox" name="Interested[]" id="protien" value="protien" />Protien
<input type="checkbox" name="Interested[]" id="creatine" value="creatine" />Creatine<br>
<input type="checkbox" name="Interested[]"  id="bcaa" value="bcaa" />BCAA
<input type="checkbox" name="Interested[]" id="power drinks" value="powerdrinks" />Power Drinks<br />
</div><!--Row-->





<br />
<div class="Row">
<div class="Lable">Where did you hear about us?</div> <!--End of Lable-->
<select>
<option value="Google" selected="selected" name="Google" id="heard"  /> Google Search
<option value="WordOfMouth" name="heard" id="WordOfMouth" /> Word of mouth 
<option value="Newspaper" name="heard" id="Neawspaper" /> Newspaper
<option value="Magazine" name="heard" id="Magazine" /> Magazine
</select>
</div><!--Row-->



<br />
<div class="submit">
<input type="submit" id="send" Name="send" value="Send" />
</div><!--End of submit-->

<div class="Clear">
<input type="reset" id="clear" Name="Clear" value="Clear" />
</div>





</form>

这是reply.php动作:

$name = $_POST["fullname"];
$email = $_POST["emailaddress"];
$comments = $_POST["comment"];
$gender = $_POST["gender"];
$age = $_POST["age"];
$Interested = $_POST['Interested'];
$heard = $_POST["heard"];


$message = "New Email for a customer" .



         "\r\nName of the contact" .
         "\r\n-". $name .
         "\r\nEmail address of the contact" . 
         "\r\n-".$email .
         "\r\nThe comment that the contact has made" . 
         "\r\n-".$comments .
         "\r\nThe gender of the contact" . 
         "\r\n-".$gender .
         "\r\nThe age range of the contact" . 
         "\r\n-".$age .
         "\r\nThe products that the customer is interested in" . 
         "\r\n-".implode(", " ,$Interested).
         "\r\nWhere the contact heard of Shredded Nutrition"  .
         "\r\n-".$Heard . 
         "\r\n-" .
  $headers =  "From: " . $email;


mail("kieran@localhost",$subject,$message,$headers);
$subjectReply = 'Thank you for your contact..';
$messageReply = 'You will soon receive an answer';
$headers = 'From: admin@shreddednutrition';

mail($email, $subjectReply, $messageReply, $headers);
?>

2 个答案:

答案 0 :(得分:3)

您的选择应命名为heard

即:

<select name="heard">

并从您的选项中删除name="heard"value会照顾到这一点。


<select name="heard">
<option value="Google" selected="selected" id="heard"  /> Google Search
<option value="WordOfMouth" id="WordOfMouth" /> Word of mouth 
<option value="Newspaper" id="Neawspaper" /> Newspaper
<option value="Magazine" id="Magazine" /> Magazine
</select>

此外,将.$Heard更改为.$heard,因为您正在使用$heard = $_POST["heard"];

更具体地说:

"\r\n-".$Heard ."\r\n-".$heard .

POST变量区分大小写。如果不这样做,您将无法在电子邮件中看到该选项。

答案 1 :(得分:0)

您的选择应该是听到的名称,而不是里面的选项。 select是实际发送回应用程序的内容,选项更多是允许用户选择的值。添加以下内容,但删除当前顶部选项中听到的ID。

<br />
<div class="Row">
<div class="Lable">Where did you hear about us?</div> <!--End of Lable-->
<select name="heard">
<option value="Google" selected="selected" name="Google"> Google Search</option>
<option value="WordOfMouth" id="WordOfMouth"> Word of mouth </option>
<option value="Newspaper" id="Neawspaper"> Newspaper</option>
<option value="Magazine" id="Magazine"> Magazine</option>
</select>
</div><!--Row-->

应解决它。