我有一个在联系表单页面上执行的 PHP 表单。我让它运行良好 - 但它目前只检查以确保输入了姓名和电子邮件。我也试图让它检查一条消息,但我的尝试只是因为页面在 php.ini 之后不加载。这是我所拥有的:
<?php
$to = "me@gmail.com" ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$startmonth = $_REQUEST['StartMonth'];
$startyear = $_REQUEST['StartYear'];
$endmonth = $_REQUEST['EndMonth'];
$endyear = $_REQUEST['EndYear'];
$message = $_REQUEST['Message'];
$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$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']);
}
$selectedNoRush = 'None';
if(isset($_POST['norush']) && is_array($_POST['norush']) && count($_POST['norush']) > 0){
$NoRush= implode(', ', $_POST['norush']);
}
$selectedWhenReady = 'None';
if(isset($_POST['whenready']) && is_array($_POST['whenready']) && count($_POST['whenready']) > 0){
$WhenReady= implode(', ', $_POST['whenready']);
}
$selectedBudget = 'None';
if(isset($_POST['budget']) && is_array($_POST['budget']) && count($_POST['budget']) > 0){
$selectedBudget= implode(', ', $_POST['budget']);
}
$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\n";
$body .= 'Start Date: ' . $startmonth . " " . $startyear . " " . $NoRush . "\n";
$body .= 'End Date: ' . $endmonth . " " . $endyear . " " . $WhenReady . "\n";
$body .= 'Budget: ' . $selectedBudget . "\n\n";
$body .= 'Message:' . $message . "\n";
$headers2 = "From: me@gmail.com";
$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 "Thank you. Your request has been successfully submitted.";}
else
{print "We encountered an error sending your mail, please check your details are correct or email us at hello@lyonempire.co.uk"; }
}
}
?>
因此,以上所有内容都可以正常工作,但是当我在名称/电子邮件检查后添加以下代码时,它会中断:
if($message == '') {print "You have not entered a message, please go back and try again";}
else {
我究竟做错了什么?
谢谢!MC