我的表单可以在我的计算机上的 Brave 中运行,但不能在我的计算机上的 Safari 或 Google 中运行。它也不适用于移动设备。如果它不起作用,它会返回 POST 409 错误。
这是我的 html 代码。
这是我的 php 代码
'error',
'text' => 'Request must come from Ajax'
));
die($output);
}
//check $_POST vars are set, exit if any missing
if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userMessage"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!'));
die($output);
}
//Sanitize input data using PHP filter_var().
$user_Name = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
$user_Email = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
$user_Phone = $_POST["userPhone"];
//$user_Subject = $_POST["userSubject"];
$user_Message = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);
//additional php validation
if(strlen($user_Name)<3) // If length is less than 3 it will throw an HTTP error.
{
$output = json_encode(array('type'=>'error', 'text' => 'Name is too short or empty!'));
die($output);
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email!'));
die($output);
}
if(strlen($user_Message)<5) //check emtpy message
{
$output = json_encode(array('type'=>'error', 'text' => 'Too short message! Please enter something.'));
die($output);
}
//Server settings
// $mail->isSMTP(); // Send using SMTP
// $mail->Host = 'smtp.googlemail.com'; // Set the SMTP server to send through
// $mail->SMTPAuth = true; // Enable SMTP authentication
// $mail->Username = '[email protected]'; // SMTP username
// $mail->Password = 'your password'; // SMTP password
// $mail->SMTPSecure = 'TLS'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
// $mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($user_Email,$user_Name);
$mail->addAddress($your_email, 'Theme Industry'); // Add a recipient
$mail->addReplyTo($your_email, 'Information');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'New Contact Inquiry from your Website';
$mail->Body = "Hi There! You have a new inquiry from your website.
";
$mail->Body .= "Name: ". $user_Name ."
";
$mail->Body .= "Email: ". $user_Email ."
";
$mail->Body .= "Phone: ". $user_Phone ."
";
$mail->Body .= "Message: ". $user_Message ."
";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send())
{
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}else{
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_Name .' Thank you for contacting us.'));
die($output);
}
}
?>
这是我的 JavaScript 代码
//contact us
$("#submit_btn1 , #submit_btn").on('click', function () {
let userName = $('#name1').val();
let userEmail = $('#email1').val();
let userMessage = $('#message1').val();
let result;
if(this.id === 'submit_btn'){
result = $('#result');
userMessage = $('#companyName').val();
userName = $('#userName').val();
userEmail = $('#email').val();
}
else{
result = $('#result1');
}
//simple validation at client's end
let postData, output;
let proceed = true;
if (userName === "") {
proceed = false;
}
if (userEmail === "") {
proceed = false;
}
if (userMessage === "") {
proceed = false;
}
//everything looks good! proceed...
if (proceed) {
//data to be sent to server
postData = {
'userName': userName,
'userEmail': userEmail,
'userMessage': userMessage
};
//Ajax post data to server
$.post('https://thordigi.com/contact.php', postData, function (response) {
//load json data from server and output message
if (response.type === 'error') {
output = '' + response.text + '';
} else {
output = '' + response.text + '';
//reset values in all input fields
$('.getin_form input').val('');
$('.getin_form textarea').val('');
}
result.slideUp("fast").html(output).slideDown();
}, 'json');
} else {
output = 'Please provide the missing fields.';
result.slideUp("fast").html(output).slideDown();
}
});
我已经被困在这个问题上有一段时间了,所以我非常感谢您的帮助!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不同的浏览器之间经常存在差异,有些浏览器比其他浏览器更宽容。像这样的错误通常是由于某些内容无法正确呈现(因此您的代码无法找到正确的字段等)。要检查 HTML,请通过 w3c 验证器运行它并查看它的建议。
如果这没有帮助,那么要准确查看每个浏览器发送和接收的内容,我建议使用中间人代理(例如 burp) 拦截请求和响应。通过查看原始数据,通常很快就能看出问题所在。