我正在尝试从头开始创建一个PHP POST电子邮件表单,而且进展顺利 - 我只是不确定如何在PHP端实现一个选择框..
以下是html中选择框的代码:
<div class="formrow">
<label class="drops">
<select name="StartMonth">
<option value="">---</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</label>
</div>
以下是整个PHP联系表格,供后人使用:
<?php
$to = "me@mycompany.co.uk" ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"Message"} = "\n" . "Message";
$selectedProjects = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
$selectedProjects = implode(', ', $_POST['projects']);
}
$selectedSkills = 'None';
if(isset($_POST['skills']) && is_array($_POST['skills']) && count($_POST['skills']) > 0){
$selectedSkills = implode(', ', $_POST['skills']);
}
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$body .= "\n" . 'Selected Projects: ' . $selectedProjects . "\n";
$body .= 'Selected Skills: ' . $selectedSkills . "\n";
$headers2 = "From: noreply@mycompany.co.uk";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{print "Success";}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?>
此外,请随时注意PHP的最佳做法,我是新手。
谢谢! MC
答案 0 :(得分:1)
我想通了,最终..我在PHP的各自部分下添加了以下内容:
$startmonth = $_REQUEST['StartMonth'];
和
$body .= 'Start Month: ' . $startmonth . "\n";
感谢Winston和Sergio,他指出了我正确的方向!