每当我在我的网站上使用联系表格时,一切都正常,除了消息。它返回[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 = "emailaddress@email.com";
$subject = "Enquiry";
$from = "emailaddress@email.com";
$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>
答案 0 :(得分:1)
使用以下内容发送数据时
data:'name='+name+'&email='+email+'&contactno='+contactno+'&message='+message1,
message1
是对span
元素的HTML id
元素的引用。您的消息似乎位于textarea
元素内id
subject
,并且您正确地获取该数据并将其存储,但您正在调用变量message
(不是message1
),所以发送数据的行应该是:
data:'name='+name+'&email='+email+'&contactno='+contactno+'&message='+message,