Ajax .Post - 将自己定义的变量发送到mail.php

时间:2014-05-18 19:14:07

标签: php html ajax email post

我从其他变量获取信息,但我想要自己发送的最后一个变量是预定义的。但由于某种原因,它不能通过mail.php

var IT1 = "IT Service" ;
//send the ajax request
$.post('mail.php',{name:$('#name').val(),
companyname:$('#companyname').val(),
designation:$('#designation').val(),
ONumber:$('#ONumber').val(),
MNumber:$('#MNumber').val(),
email:$('#e-mail').val(),
message:$('#message').val(),
Manage:$('#Manage1').val(),
Tech:$('#Tech1').val(),
IT:$IT1},

mail.php看起来像:

<?php
// declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$message = nl2br($_POST['message']);
$companyname = $_POST['companyname'];
$designation = $_POST['designation'];
$ONumber = $_POST['ONumber'];
$MNumber = $_POST['MNumber'];
$IT = $_POST['IT'];
$Tech = $_POST['Tech'];
$Manage = $_POST['Manage'];

// set a title for the message
$subject = "Message from Your Website";
$body = "Name: $name\r\n, 
E-mail: $email\r\n, 
Company Name: $companyname\r\n, 
Designation: $designation\r\n, 
Office Number: $ONumber\r\n, 
Mobile: $MNumber\r\n,
Services: $IT, $Tech, $Manage\r\n,
Message: \n\n$message\r\n";

1 个答案:

答案 0 :(得分:0)

您应该遵循其他变量的格式:

IT:$('#IT1').val() }

IT:$(IT1).val() }