【发布时间】:2016-02-03 05:40:04
【问题描述】:
我有一份包含大量输入字段的问卷。到目前为止,我启动了一个 PHP 脚本将其发送到我的电子邮件,如下所示。
<?php
$First_Name= $_POST['First_Name'];
$Last_Name= $_POST['Last_Name'];
$E_Mail= $_POST['E_Mail'];
$FB_Name= $_POST['FB_Name'];
$Twitter_Name= $_POST['Twitter_Name'];
$Country= $_POST['Country'];
$State_Province= $_POST['State_Province'];
$City= $_POST['City'];
$Phone_01= $_POST['Phone_01'];
$Phone_02= $_POST['Phone_02'];
$Phone_03= $_POST['Phone_03'];
$How_did_you_hear_about_my_Company= $_POST['How_did_you_hear_about_my_Company'];
$Operating_your_Business= $_POST['Operating_your_Business'];
$Name_for_your_Business= $_POST['Name_for_your_Business'];
$Whats_the_name_of_your_Business= $_POST['Whats_the_name_of_your_Business'];
$What_type_of_Business= $_POST['What_type_of_Business'];
$Type_of_Business_you_run= $_POST['Type_of_Business_you_run'];
$How_long_you_been_building= $_POST['How_long_you_been_building'];
$How_long_you_been_in_business= $_POST['How_long_you_been_in_business'];
$What_do_you_plan_to_offer= $_POST['What_do_you_plan_to_offer'];
$What_do_you_offer= $_POST['What_do_you_offer'];
$List_all_products_you_offer['List_all_products_you_offer'];
$from = 'From: Your_New_Client';
$to = 'Optiqvision@gmail.com';
$subject = 'A New Questionnaire';
$body = "Name: $First_Name $Last_Name
\n E-Mail: $E_Mail
\n FB Name: $FB_Name
\n Twitter Name: $Twitter_Name
\n Country: $Country
\n State/Province: $State_Province
\n City: $City
\n Phone Number: $Phone_01 $Phone_02 $Phone_03
\n How did you hear about my Company?:\n\n $How_did_you_hear_about_my_Company
\n Where are you in terms of opperating your Business?: $Operating_your_Business
\n Have you come up with a name for your Business?: $Name_for_your_Business
\n What's the name of your Business?: $Whats_the_name_of_your_Business
\n What type of Business will you be running?: $What_type_of_Business
\n What type of Business do you run?: $Type_of_Business_you_run
\n How long have you been Building your Business?: $How_long_you_been_building
\n How long have you been in Business?: $How_long_you_been_in_business
\n What do you plan to offer?: $What_do_you_plan_to_offer
\n What do you offer?: $What_do_you_offer
\n List of products: $List_all_products_you_offer
";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
这可以正常工作,但我想知道如何告诉 PHP 自动收集所有数据,而不必逐个处理每个元素(比上面表示的要多得多)。
我遇到了一个用于存储到 SQL 数据库的脚本,但不是用于电子邮件的脚本。我尝试将它用于 SQL,但由于它创建了多少列而遇到了问题。
除此之外,我还有另一项任务要处理,即允许用户添加因用户而异的字段,因此我需要 $POST 方法灵活,以便它可以发送结果。以我到目前为止的编码方式,当用户添加额外的字段时,无法发布它们。
我在该网站上进行了搜索,到目前为止,这是我遇到的唯一与此问题相关的内容,但并不真正理解所讲的内容。 PHP: Possible to automatically get all POSTed data?
如果这确实是我正在尝试做的事情的答案,有人可以再分解一下并告诉我它是如何工作的吗?
【问题讨论】: