每当我在我的网站上使用联系表时,除消息外,其他所有功能都工作正常。它正在返回[object HTMLSpanElement]

这是我创建的单独文件mail.js的代码,因为我也使用此文件进行错误处理。

function submit_form()
{
var letters = /^[A-Za-z]+$/;
var message     =   document.getElementById('subject').value;

$.ajax({
type:'post',
url:'enquiry.php',
data:'name='+name+'&email='+email+'&contactno='+contactno+'&message='+message1,
success:function(data)
{
if(data=="1")
{
//document.getElementById('success').innerHTML="Your message has been sent successfully.";
$('#success').html("Your message has been sent successfully.")


这是enquiry.php的代码

$name           =   $_POST['name'];
$email          =   $_POST['email'];
$contactno      =   $_POST['contactno'];
$message1       =   $_POST['message'];
$to         =   "[email protected]";
$subject    =   "Enquiry";
$from       =   "[email protected]";
$message = "
<html>
<head>
<title>ENQUIRY</title>
</head>
<body>
<h4>ENQUIRY</h4>
<b>Full Name</b>: $name<br />
<b>Email Id</b>: $email<br />
<b>Contact</b>: $contactno <br />
<b>Message </b>: $message1<br />
</body>
</html>";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;

if(mail($to,$subject,$message,$headers))
{
    echo 1;
}


这是该HTML

<input type="text" name="contactno" maxlength="10" pattern="[1-9]{1}[0-9]{9}" id="contactno" placeholder="Enter 10 digit Contact Number" class="footer-form1" value="" onchange="removeerr();" required><br>
<span id="contact1"></span>

<textarea id="subject" name="message" id="subject" placeholder="Write your message here.." class="footer-massage" value="" onchange="removeerr();" required></textarea>
<span id="message1"></span>
<span id="success"></span>

最佳答案

使用以下方式发送数据时:

data:'name='+name+'&email='+email+'&contactno='+contactno+'&message='+message1,


message1是对该span的HTML id元素的引用。您的消息似乎位于textarea元素的内部,且idsubject,并且您正确获取了该数据并将其存储,但是您正在调用变量message(不是message1),因此发送数据的行应为:

data:'name='+name+'&email='+email+'&contactno='+contactno+'&message='+message,

08-19 13:19