0

我的 PHP 文件中有一个 ajax 帖子用于发送电子邮件。问题是,我的 html 联系表单总是在变化,一个用户可能使用 10 个文本输入,另一个用户可能使用 5 个,等等。

数据像这样进入 PHP 文件:

txt1=John&txt2=aol@aol.com&txt3=5550123944&dropDown1=Sales&question=How+are+you

PHP 文件是这样的:

<?php
$emailSubject = 'Customer Has a Question!';
$webMaster = 'giberisk@yahoo.com';

$name = $_POST ['name'];
$email = $_POST['email'];
$phone = $_POST ['phone'];
$question = $_POST ['question'];


$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Question: $question <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
EOD;
echo "$theResults";
?> 

我必须做什么,以便 PHP 文件找出传递了多少个参数,并在这些参数的名称之后命名变量?

我希望我足够清楚,

提前致谢

4

1 回答 1

1

你可以做foreach,比如

$count = count($_POST); //shows number of variables POST'ed
foreach($_POST as $key => $val ) {
   echo $key . "==>" .$val;   
   //or assign values to key variables
   ${$key} = $value; //${$key} will be variable holding $value as value
}
于 2013-01-31T04:31:44.653 回答