我有一个表格,它使用 php 向自己发送电子邮件询问。我有一些将详细信息填写到 div 中的 jquery,
如何通过 ajax 将 Jquery var 传递给 PHP?(我读过这是最好的方法?)
这是使用 php 向我发送电子邮件的方式:
<? if(isset($_POST['submit'])) {
$to = "rob@domain.com";
$header = 'From: rob@domain.com';
$subject = "Quotation";
$enquiry_first_name = $_POST['enquiryfirstname'];
$enquiry_last_name = $_POST['enquirylastname'];
$enquiry_title = $_POST['enquirytitle'];
$enquiry_organisation = $_POST['enquiryorganisation'];
$enquiry_address = $_POST['enquiryaddress'];
$enquiry_country = $_POST['enquirycountry'];
$enquiry_email_address = $_POST['enquiryemailaddress'];
$enquiry_telephone = $_POST['enquirytelephone'];
$enquiry_additional_comments = $_POST['enquiryadditionalcomments'];
$body = "You have an quote request from the website:
Name: $enquiry_title $enquiry_first_name $enquiry_last_name
Type of organisation: $enquiry_organisation
Address: $enquiry_address, $enquiry_country
E-Mail: $enquiry_email_address
Tel: $enquiry_telephone
Comments: $enquiry_additional_comments
Kind regards";
mail($to, $subject, $body, $header);
echo "Thank you for your enquiry.";
} ?>
这是将数据输出到 div 的 jquery:
function makeSummary() {
var summary = [];
$steps.not(":last").each(function (i, step) {
$step = $(step);
summary.push('<p><b>' + $step.data('name') + '</b></p>');
var $ch = $step.find('input[type="checkbox"]:checked');
if (!$ch.length) {
summary.push('<p>No items selected</p>');
} else {
$ch.each(function (i, ch) {
summary.push('<p>' + $(ch).val() + '</p>');
});
}
});
return summary.join('');
}