有一个表格,用户在其中选择所需的许可证数量、总费用等,输入姓名、电话号码和邮件,然后将其发送到我的邮箱。问题是只有姓名和邮件字段的信息才能进入邮件,其余的都是空的。
我不明白可能是什么问题,请帮忙)标记:
<form id="contact_form" method="post" action="php/mail.php">
<input type="button" value="−" id="minus" class="mycount button-minus">
<p id="count" name="lisence_count" class="mycount simple-count">1</p>
<input type="button" value="+" id="plus" class="mycount button-plus">
<input type="text" id="name" name="name" class="myinfo" placeholder="Ваше имя">
<input type="text" id="phone" name="phone" class="myinfo" placeholder="Телефон">
<input type="email" id="email" name="email" class="myinfo" placeholder="Email">
<button type="submit" id="send-button" class="submit-button">Подключить<span id="current-price" name="price" class="tarif-price">$10</span></button>
</form>
JS:
$('#contact_form .submit-button').on('click', function() {
//берем путь php обработчика
order_url = $('#contact_form').attr('action');
//посылаем асинхронный запрос на сервер и передаем все данные формы
$.post(order_url,{
name: $('#contact_form input[name=name]').val(),
tel: $('#contact_form input[name=phone]').val(),
email: $('#contact_form input[name=email]').val(),
lisence_count: $('#contact_form #count').val(),
price: $('#contact_form #current-price').val(),
send: "1"
}, "html");
return false;
});
PHP:
header('Content-type: text/html; charset=utf-8');
error_reporting(0);
if(!empty($_POST['send'])) {
$name = substr(htmlspecialchars(trim($_POST['name'])), 0, 300);
$tel = substr(htmlspecialchars(trim($_POST['phone'])), 0, 100);
$email = substr(htmlspecialchars(trim($_POST['email'])), 0, 100);
$lisence = substr(htmlspecialchars(trim($_POST['lisence_count'])), 0, 100);
$price = substr(htmlspecialchars(trim($_POST['price'])), 0, 100);
$ip = $_SERVER['REMOTE_ADDR'];
$mess = "Имя: <b>".$name."</b><br />";
$mess .= "Телефон: <b>".$tel."</b><br />";
$mess .= "Email: <b>".$email."</b><br />";
$mess .= "Количество лицензий: <b>".$lisence."</b><br />";
$mess .= "Цена: <b>".$price."</b><br />";
mail("thisismymail@gmail.com", $theme, $mess, "From: GSuite \nContent-Type: text/html;\n charset=utf-8\nX-Priority: 0");
}
else {
echo "<h2>Ошибка! Попробуйте еще раз.</h2>";
}
空,因为:
$('#contact_form #count').val()
这是一个段落,所以undefined
这是一个标签
span
,所以它$('#contact_form #current-price').val()
会是undefined
电话是空的,因为在您传递的 POST 请求中
tel
在php中你试图得到
phone