0 php forms redirect location header
试图在我的头命令中找到我的重定向不能正常工作.表单发送信息,但从不重定向到登录页面.我仍然用PHP代码在耳朵后面湿透,所以请对我的无知感到不满.HH
<?php
// Get email address
require_once 'config.php';
// Ensures no one loads page and does simple spam check
if( isset($_POST['name']) && empty($_POST['spam-check']) ) {
// Declare our $errors variable we will be using later to store any errors
$error = '';
// Setup our basic variables
$input_name = strip_tags($_POST['name']);
$input_email = strip_tags($_POST['email']);
$input_subject = strip_tags($_POST['subject']);
// We'll check and see if any of the required fields are empty
if( strlen($input_name) < 2 ) $error['name'] = 'Please enter your name.';
// Make sure the email is valid
if( !filter_var($input_email, FILTER_VALIDATE_EMAIL) ) $error['email'] = 'Please enter a valid email address.';
// Set a subject & check if custom subject exist
$subject = "Message from $input_name";
if( $input_subject ) $subject .= ": $input_subject";
$message = "$input_message\n";
$message .= "\n---\nThis email was sent by contact form.";
// Now check to see if there are any errors
if( !$error ) {
// No errors, send mail using conditional to ensure it was sent
if( mail($your_email_address, $subject, $message, "From: $input_email") ) {
echo '<p class="success">Your email has been sent!</p>';
}
else {
echo '<p class="error">There was a problem sending your email!</p>';
}
}
else {
// Errors were found, output all errors to the user
$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 /> \n" : null;
echo "<p class='error'>$response</p>";
}
}
else {
die('Direct access to this page is not allowed.');
header("Location: http://jjco.energy526.com/Introduction.aspx");
exit;
}
Run Code Online (Sandbox Code Playgroud)
您die在调用标头之前使用意味着您永远不会执行header调用.
| 归档时间: |
|
| 查看次数: |
571 次 |
| 最近记录: |