Javascript 在两台不同的服务器上使用相同的联系方式,但其中一台没有';不发送
正如标题所说,我在html模板中遇到了两个相同的联系人表单的问题 我服务器上的一个可以正常工作,但在我客户端的服务器上它不发送邮件并返回错误 这是我的密码:Javascript 在两台不同的服务器上使用相同的联系方式,但其中一台没有';不发送,javascript,php,html,ajax,email,Javascript,Php,Html,Ajax,Email,正如标题所说,我在html模板中遇到了两个相同的联系人表单的问题 我服务器上的一个可以正常工作,但在我客户端的服务器上它不发送邮件并返回错误 这是我的密码: <form id="contactForm" data-toggle="validator"> <div class="form-group"> <!-- First Name Field --> <input type="text" id="name" pl
<form id="contactForm" data-toggle="validator">
<div class="form-group">
<!-- First Name Field -->
<input type="text" id="name" placeholder="Name*" required="" size="35" data-error="Name is required">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<!-- Phone Number Field -->
<input type="tel" id="phone" placeholder="Phone Number*" required="" size="35" data-error="Phone Number is required">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<!-- Email Field -->
<input type="email" id="email" required="" placeholder="Email*" data-error="Email is required" size="35">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<!-- Message Field -->
<textarea id="message" name="message" placeholder="Message*" data-error="Message cannot be empty"></textarea>
<div class="help-block with-errors"></div>
<p class="subtle">*required fields</p>
<!-- Submit Button -->
<button type="submit" class="button">GET ACCESS & BUYERS GUIDE NOW!</button>
<!-- Success Message -->
<div id="msgSubmit" class="text-center hidden"></div>
</div>
</form>
// FORM SCRIPTS
$("#contactForm").validator().on("submit", function(event) {
if (event.isDefaultPrevented()) {
// handle the invalid form...
formError();
submitMSG(false, "Did you fill in the form properly?");
} else {
// everything looks good!
event.preventDefault();
submitForm();
}
});
function submitForm() {
// Initiate Variables With Form Content
var name = $("#name").val();
var phone = $("#phone").val();
var email = $("#email").val();
var message = $("#message").val();
$.ajax({
type: "POST",
url: "php/form-process.php",
data: "name=" + name + "&phone=" + phone + "&email=" + email + "&message=" + message,
success: function(text) {
if (text === "success") {
formSuccess();
} else {
formError();
submitMSG(false, text);
}
}
});
}
function formSuccess() {
$("#contactForm")[0].reset();
submitMSG(true, "Success!")
}
function formError() {
$("#contactForm").one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
$(this).removeClass();
});
}
function submitMSG(valid, msg) {
if (valid) {
var msgClasses = "h4 text-center text-success";
} else {
var msgClasses = "h4 text-center text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
*必填字段
获取访问权限&;买家指南现在!
//表单脚本
$(“#contactForm”).validator()。在(“提交”时,函数(事件){
if(event.isDefaultPrevented()){
//处理无效的表单。。。
formError();
submitMSG(错误,“您是否正确填写了表格?”);
}否则{
//一切看起来都很好!
event.preventDefault();
submitForm();
}
});
函数submitForm(){
//使用表单内容初始化变量
var name=$(“#name”).val();
var phone=$(“#phone”).val();
var email=$(“#email”).val();
var message=$(“#message”).val();
$.ajax({
类型:“POST”,
url:“php/form process.php”,
数据:“name=“+name+”&phone=“+phone+”&email=“+email+”&message=“+message,
成功:函数(文本){
如果(文本==“成功”){
formSuccess();
}否则{
formError();
提交TMSG(错误,文本);
}
}
});
}
函数formSuccess(){
$(“#contactForm”)[0]。重置();
submitMSG(正确,“成功!”)
}
函数formError(){
$(“#contactForm”).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd OAAnimationEnd animationend',函数(){
$(this.removeClass();
});
}
函数submitsg(有效,消息){
如果(有效){
var msgClasses=“h4文本中心文本成功”;
}否则{
var msgClasses=“h4文本中心文本危险”;
}
$(“#msgSubmit”).removeClass().addClass(msgClasses).text(msg);
}
还有PHP代码
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required";
} else {
$name = $_POST["name"];
}
// PHONE
if (empty($_POST["phone"])) {
$errorMSG = "Phone Number is required";
} else {
$phone = $_POST["phone"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG = "Email is required";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG = "Message cannot be empty";
} else {
$message = $_POST["message"];
}
$EmailTo = "gs@inproperty-spain.com";
$subject = "Contact Form: $name";
$headers = 'From: gs@inproperty-spain.com' . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Phone Number: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
$Body .= "\n";
$Body .= $headers;
// send email
$success = mail($EmailTo, $subject, $Body, $headers);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
?>
尝试提交表单时返回“出现问题:(”
我在两台服务器上都做了phpinfo,客户端的一台使用php7.3.10,而我的服务器在7.0.33上运行
有人知道发生了什么吗
非常感谢可能邮件选项设置错误。您是否在服务器错误日志中看到任何消息?问题似乎是电子邮件功能返回错误,电子邮件服务器是否正在运行?请检查此页面将对您有所帮助