一切正常,直到我在电话号码的字段中添加。如果我将其删除,则会发送电子邮件。
我输了=' tel'但它也没有用。我尝试了我可以找到的任何变种来解决问题,唯一可行的是从html和php中删除所有电话字段的痕迹。
HTML:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" enctype="multipart/form-data">
<div class="form-group">
<input type="text" class="form-control" id="Name" name="name" placeholder="Name" required="required">
</div>
<div class="form-group">
<input type="email" class="form-control" id="Email" name="email" placeholder="Email">
</div>
<div class="form-group">
<input type="text" class="form-control" id="Phone" name="phone" placeholder="PhoneNumber">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" name="message" placeholder="Message" required="requried"></textarea>
</div>
<button type="submit" name="submit" class="btn-block" >Send</button>
</form>
PHP(代码段):
$name = @trim(stripslashes($_POST['name']));
$clientemail = @trim(stripslashes($_POST['email']));
$phone = (stripslashes($_POST['phone']));
$message = @trim(stripslashes($_POST['message']));
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $clientemail . "\n\n" . 'Phone: ' . $phone . "\n\n" . 'Message: ' . $message;
$email = new PHPMailer();
$email->From = $clientemail;
$email->FromName = $name;
$email->Subject = 'Message from Website User';//$subject;
$email->Body = $body;
$email->AddAddress( 'johndoe@gmail.com' ); //Send to this email
// EXPLICITLY TELL PHP-MAILER HOW TO SEND THE EMAIL... IN THIS CASE USING PHP BUILT IT MAIL FUNCTION
$email->isMail();
header("Content-Type: application/json; charset=utf-8", true);
// NOW, TRY TO SEND THE EMAIL ANYWAY:
try{
$success = $email->send();
$status['type'] = 'success';
$status['message'] = 'Thank you for contacting us. We will reply as soon as possible.';
}catch(Exception $e){
$status['type'] ='Error';
$status['message'] ='Couldn\'t send the Email at this Time. Something went wrong';
}
// SIMPLY, RETURN THE JSON DATA...
die(json_encode($status));
这是我的JS / AJAX:
/***************** Contact Form Submission ******************/
$(document).ready(function (e){
$("#main-contact-form").on('submit',(function(e){
e.preventDefault();
$('#sendingemail').fadeIn();
$.ajax({
url: "../sendemail.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data){
console.log(data);
if (data.type == 'Error') {
//alert(data.message);
$('#sendingemail').fadeOut();
$("#notsent").html(data.message).fadeIn();
}
else{
$('#sendingemail').fadeOut();
$('#emailsent').fadeIn();
//alert(data.message);
}
},
error: function(XHR,textStatus,errorThrown) {
//alert("error");
console.log(XHR.status + "..." + textStatus + "..." + errorThrown);
alert(XHR.status);
alert(textStatus);
alert(errorThrown);
}
}
);
}));
});