我在我的网站上(从模板)实施了以下联系表格,我可以成功发送和接收电子邮件,但我的收件箱中未收到邮件部分(用户文本)。 我收到了姓名和电子邮件,但没有收到邮件的内容。
screenshot from the website form
有人可以帮助查找和解决问题吗?它是php,jQuery还是html错误?
HTML:
<form action="contact.php" class="contact_form" id="form" method="post">
<div class="col-lg-6 col-md-6 col-lg-offset-3 col-md-offset-3">
<span class="input input_name">
<input class="input__field" type="text" name="name" id="name" required/>
<label class="input__label" for="name">
<span class="input__label_content">Name</span>
</label>
</span>
<span class="input input_website">
<input class="input__field" type="url" name="website" id="website" />
<label class="input__label" for="website">
<span class="input__label_content">Website</span>
</label>
</span>
<span class="input input_mail">
<input class="input__field" type="email" name="email" id="email" required/>
<label class="input__label" for="email">
<span class="input__label_content">email</span>
</label>
</span>
</div>
<div class="col-lg-8 col-md-8 col-lg-offset-2 col-md-offset-2">
<span class="textarea">
<textarea class="textarea_field" name="textarea" id="textarea" rows="4" placeholder="type your text here . . . ."></textarea>
</span>
<span class="submit">
<button type="submit" class="rms-btn submit_btn" id="submit">submit request <span><i class="fa fa-pencil"></i></span></button>
</span>
</div>
</form>
contact.php:
<?php
/*
* Ajax form submit
*/
# request sent using HTTP_X_REQUESTED_WITH
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ){
if (isset($_POST['name']) AND isset($_POST['email']) AND isset($_POST['textarea'])) {
$to = 'info@antarescodestudio.com'; /* Add your contact email address here */
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['textarea'], FILTER_SANITIZE_STRING);
$sent = email($to, $email, $name, $message);
if ($sent) {
echo 'Message sent!';
} else {
echo 'Message couldn\'t sent!';
}
}
else {
echo 'All Fields are required';
}
return;
}
/**
* email function
*
* @return bool | void
**/
function email($to, $from_mail, $from_name, $subject, $message){
$header = array();
//$header[] = "MIME-Version: 1.0";
$header[] = "From: {$from_name} < {$from_mail}>";
$header[] = "Message: {$message}";
/* Set message content type HTML*/
/*$header[] = "Content-type:text/html; charset=iso-8859-1";*/
/*$header[] = "Content-Transfer-Encoding: 7bit";*/
if( mail($to, $message, implode("\r\n", $header)) ) return true;
}
?>
contact.js
jQuery(document).ready(function() {
var form = jQuery('#form'); // contact form
var submit = jQuery('#submit'); // submit button
var alert = jQuery('.alert'); // alert div for show alert message
// form submit event
form.on('submit', function(e) {
e.preventDefault(); // prevent default form submit
// sending ajax request through jQuery
jQuery.ajax({
url: 'contact.php', // form action url
type: 'POST', // form submit method get/post
dataType: 'html', // request type html/json/xml
data: form.serialize(), // serialize form data
beforeSend: function() {
alert.fadeOut();
submit.html('Sending....'); // change submit button text
},
success: function(data) {
alert.html(data).fadeIn(); // fade in response data
form.trigger('reset'); // reset form
submit.html('Email Sent <span> <i class="fa fa-check"></i> </span>'); // reset submit button text
},
error: function(e) {
console.log(e)
}
});
});
});
谢谢!
答案 0 :(得分:0)
替换
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
与
$message = filter_var($_POST['textarea'], FILTER_SANITIZE_STRING);
修改:此行也值得怀疑:
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
没有名称为subject
的字段。
答案 1 :(得分:0)
您的文本区域名称为“textarea”,而在您的php文件中,您正在处理$_POST['message']
。将textarea的名称更改为“消息”或将$_POST['message']
更改为$_POST['textarea']
答案 2 :(得分:0)
我看起来textarea是表单上的名称textarea
,但是您引用了一个名为message
的POST变量。