函数constructMessageBody
用于从联系人创建电子邮件的正文文本。该表单包含必填字段和非必填字段,但只有它只将必填字段添加到电子邮件正文中。
function constructMessageBody () {
$fields_req = array("addressline1" => true, "postcode" => true, "priority" => true, "description" => true, "email" => true);
$message_body = "";
foreach ($fields_req as $name => $required) {
$postedValue = $_POST[$name];
if ($required && empty($postedValue)) {
errorResponse("$name is empty.");
} else {
$message_body .= ucfirst($name) . ": " . $postedValue . "\n";
}
}
return $message_body;
}
答案 0 :(得分:2)
在$fields_req
数组中添加表单的每个输入字段。那些不需要的内容将它们添加为"field" => false
:
$fields_req = array("addressline1" => true, "field2" => false, "postcode" => true);