PHP未定义变量:错误

时间:2018-01-29 03:38:57

标签: php variables undefined

我在以下代码行中收到未定义的变量错误。我个人花了几个小时尝试自己解决它,但由于某种原因我无法找到解决方案。我确信这看起来很简单。任何帮助或建议将不胜感激。在此先感谢您的时间。我为这种糟糕的格式道歉,因为它没有成功。

以下代码行中的未定义变量错误:

$ message。=“来自的电子邮件:”。 $ name。 “< br />”;

if(!$ error){

==================================

$name = trim(stripslashes($_POST['CName']));
$email = trim(stripslashes($_POST['CEmail']));
$subject = trim(stripslashes($_POST['CSubject']));
$contact_message = trim(stripslashes($_POST['CMessage']));

// Check Name
if (strlen($name) < 2) {
    $error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
    $error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
    $error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }


// Set Message
$message .= "Email from: " . $name . "<br />"; 
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

// Set From: headers
$from =  $name . " <" . $email . ">";

// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

if(!$ error){

    ini_set("sendmail_from", $siteOwnersEmail); // for windows server
    $mail = mail($siteOwnersEmail, $subject, $message, $headers);

    if ($mail) { echo "OK"; }
    else { echo "Something went wrong. Please try again."; }

} # end if - no validation error

else {

    $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
    $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
    $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;

    echo $response;

} # end if - there was a validation error

}

&GT;

0 个答案:

没有答案