• 0

Help making a Q&A Form


Question

I'm looking for someone that knows how to setup a basic HTML layout that will use a php file or not in which there will be 10 Questions. The boxes for text will be of enough to put in a few sentences as needed to place answers in and once these answers are all filled in click Submit and it sends the questions along side the results to an email of my choice.

I've set up a few feedback forms from templates I've found online but editing them so far has drove me nuts as the form doesn't seem to be sending. If you know how to do this please PM me...you can just put in temp questions and a temp email I'll edit them later.

I only need a total of 10 Question slots

This is basically going to be used on a site that has full up to date php versions etc etc..so don't worry about that.

Thanks

Here is the code if someone can see what is wrong.

This is the html file named - Tier2Application.html



<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">

<tbody><tr>
<td valign="top">
<label for="age">What is your age? </label>
</td>
<td valign="top">
<input type="text" name="age" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="top" "="">
<label for="Time_Zone">What Time Zone/Country do you live in? </label>
</td>
<td valign="top">
<input type="text" name="Time_Zone" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="Extra_abilities">What other servers do you currently have extra abilities with ie: VIP, Donator, Admin etc etc? </label>
</td>
<td valign="top">
<textarea type="text" name="Extra_abilities" maxlength="1000" cols="25" rows="6"><textarea>
</td>

</tr>
<tr>
<td valign="top">
<label for="position">Tell us why you think you should hold this position.</label>
</td>
<td valign="top">
<textarea type="text" name="position" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="dedicate">How much time do you dedicate to our Servers in a week?</label>
</td>
<td valign="top">
<input name="dedicate" maxlength="70" size="30">
</td>
<tr>
<td valign="top">
<label for="improve">Tell us how you could help us to improve our community and servers.</label>
</td>
<td valign="top">
<textarea type="text" name="improve" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="Opinion">What do you think of the servers at this time?</label>
</td>
<td valign="top">
<textarea type="text" name="Opinion" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="Duration">How long have you been a part of this function?</label>
</td>
<td valign="top">
<textarea type="text" name="Duration" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="Rep_Thread">Do you have a site? If so please provide URL.</label>
</td>
<td valign="top">
<textarea type="text" name="Rep_Thread" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="populate">What suggestions would you give to enhance the servers to help populate them more?</label>
</td>
<td valign="top">
<textarea type="text" name="populate" maxlength="1000" cols="30" rows="6"><textarea>
</td>
</tr>

</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> ( <a href="http://www.none.com">none</a> )
</td>
</tr>
</table>
</form>
[/CODE]

here is the php file named html_form_send.php

[CODE]
<?php
if(isset($_POST['email'])) {

// CHANGE THE TWO LINES BELOW
$webmaster_email = "[email protected]";

$email_subject = "Tier2 Application";


function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.

";
echo $error."

";
echo "Please go back and fix these errors.

";
die();
}

// validation expected data exists
if(!isset($_POST['age']) ||
!isset($_POST['Time_Zone']) ||
!isset($_POST['Extra_abilities']) ||
!isset($_POST['position']) ||
!isset($_POST['dedicate']) ||
!isset($_POST['improve']) ||
!isset($_POST['Opinion']) ||
!isset($_POST['Duration']) ||
!isset($_POST['Rep_Thread']) ||
!isset($_POST['populate'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$age = $_POST['age']; // required
$Time_Zone = $_POST['Time_Zone']; // required
$Extra_abilities = $_POST['Extra_abilities']; // required
$position = $_POST['position']; // required
$dedicate = $_POST['dedicate']; // required
$improve = $_POST['improve']; // required
$Opinion = $_POST['Opinion']; // required
$Duration = $_POST['Duration']; // required
$Rep_Thread = $_POST['Rep_Thread']; // required
$populate = $_POST['populate']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';[/size][/font]
[font="Verdana"][size="2"] }
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($Time_Zone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "position: ".clean_string($position)."\n";
$email_message .= "dedicate: ".clean_string($dedicate)."\n";
$email_message .= "improve: ".clean_string($improve)."\n";
$email_message .= "Opinion: ".clean_string($Opinion)."\n";
$email_message .= "Duration: ".clean_string($Duration)."\n";
$email_message .= "Rep_Thread: ".clean_string($Rep_Thread)."\n";
$email_message .= "populate: ".clean_string($populate)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- place your own success html below -->

Thank you for the application. We will be in touch with you very soon.

<?php
die();
?>
[/CODE]

Be sure to remove this from the code above at the bottom cause for some stupid reason it keeps adding it to the code

/size /font font=verdana size=2 ALL THIS WITHOUT THE BRACKETS...damn stuff!!</textarea></td></tr></tbody></table></form>

Link to comment
https://www.neowin.net/forum/topic/1079759-help-making-a-qa-form/
Share on other sites

12 answers to this question

Recommended Posts

  • 0

I'm looking through it, but could you say exactly what problems you're having with it? is the email just not sending, or are you getting an error or what?

EDIT: try changing "@mail(blahblahblah);" to just "mail(blahblahblah);" (remove the @ sign). that way you'll see any errors that happen :)

Edited by Matthew_Thepc
  • 0

  • look through all the $_POST['something'] and make sure that everything there is spelt exactly the same as the "name" property in your HTML form
  • take away the "@" from before mail so you'll know if there are any errors
  • move the } after the $email_exp line to right before the first ?> (the one after the mail line, not the one after the die())
  • I'd suggest changing all the $variable = something; to lowercase so you don't get mixed up (ex. change like 26 from $Rep_Thread = $_POST['Rep_Thread']; to $rep_thread = $_POST['Rep_Thread']; and then changing all instances of $Rep_Thread to $rep_thread (easily done through find & replace). This isn't necessary, but it's nice to have all of your code either capitalized or non-capitalized.

If none of this works, make SURE you've taken away the @ from before mail( and then check again to see if there are any errors

  • 0
  • look through all the $_POST['something'] and make sure that everything there is spelt exactly the same as the "name" property in your HTML form
  • take away the "@" from before mail so you'll know if there are any errors
  • move the } after the $email_exp line to right before the first ?> (the one after the mail line, not the one after the die())
  • I'd suggest changing all the $variable = something; to lowercase so you don't get mixed up (ex. change like 26 from $Rep_Thread = $_POST['Rep_Thread']; to $rep_thread = $_POST['Rep_Thread']; and then changing all instances of $Rep_Thread to $rep_thread (easily done through find & replace). This isn't necessary, but it's nice to have all of your code either capitalized or non-capitalized.

If none of this works, make SURE you've taken away the @ from before mail( and then check again to see if there are any errors

Ok I've gone thru and did each of these... did find some errors in wording for what I used on the names of each instance but also went and changed the caps or removed them and double checked all the spelling I don't see any issues. I removed the @ but nothing showed of an error and just processed it with the "Thanks" message at the top of the next screen like nothing happened but no email sent.

Suggestions?

  • 0

Where are $email_from and $email_to coming from? I don't see them being filled up anywhere.

Also the if($_POST['email']) on the top: There's no input named email in your form, so it'll never evaluate to true.

The @mail call is outside that if though, so it'll try sending regardless. (Well you fixed this one if you moved the } as said above)

Also the mail function returns false if there are errors with the message to send. You can check for that :)

  • 0

Where are $email_from and $email_to coming from? I don't see them being filled up anywhere.

Also the if($_POST['email']) on the top: There's no input named email in your form, so it'll never evaluate to true.

The @mail call is outside that if though, so it'll try sending regardless. (Well you fixed this one if you moved the } as said above)

Also the mail function returns false if there are errors with the message to send. You can check for that :)

Yeah I did the change of moving the } and the mail function isnt' returning any errors when sent...it just processes saying "Thanks for sending blah blah" but no email received.

  • 0

Ok.... I would like to think of myself as being really good with this kind of stuff.

My suggestion would be make it simple...

strip everything you don't need.

That way you will find the problem/error faster and then just fix in the longer version.

I believe the issue is that the function is never call... i.e. it will ever evaluate to true if(isset($_POST['email'])) {

like someone else pointed out.

Reason: There is no form element called email being sent, unless i missed it but i did a find on this page.

Also email is a reserved word!!! this has bitten me so many times its not funny.... now when it comes to email/e-mail I always prefix or suffix it.

so change email to something like QandA_email... your probably find it start working.

Remember this

form elements are identified by their name not there ID.... well i could stand corrected... but it is the name in some of my stuff...

I usually include both.

so

<input id="QandA_email" type="text" name="QandA_email" class="default_email" value="" placeholder="Email Address" />

remember to change if(isset($_POST['email'])) { to if(isset($_POST['QandA_email'])) {

also i always do this for debugging.

$QandA_email = $_POST['QandA_email']

echo $QandA_email;

if(QandA_email) {

}

PS!!! my PHP is super rusty... so i might be off.... I'm into C# now

hope this helps

after re-reading it

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

?>

i think your problem is most likely here.

as someone already pointed out .$email_from is never set

$email_from = $_POST['QandA_email']

or

$email_from = $_POST['email_from '] as long as you don't use plain email or e-mail

remember the form must correspond to this

as someone said ... sozs been re-reading the code..

$email_to

this is not set either so

$email_to = "[email protected]";

so final conclusion:

  • Add form element name it "email_to"
  • add this before the if, $email_to = $_POST['email_to']
  • then evaluate if($email_to).....

the above gets tricky but for the stakes of keeping it simple.

you may have to check this as i would write this in c# as if ($email_to != "").

tricky?... is it an e-mail... validation needed here.. also in PHP does no empty string evaluate to false...?

  • 0

I fixed it.. I went with this more simple layout for php


<?PHP
$to = "[email protected]";
$subject = "Form App";
$headers = "From: Form App";
$forward = 0;
$location = "";

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$msg = "Below is the result of a form. It was submitted on $date at $time.\n\n";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting the form. We will get back to you as soon as possible.";
}

?>
[/CODE]

Thanks to all that helped!

  • 0

Great stuff... that you got it stored...

Again don't know too much about PHP..

But to me...this is retarded being used here...

if ($_SERVER['REQUEST_METHOD'] == "POST") {

foreach ($_POST as $key => $value) {

$msg .= ucfirst ($key) ." : ". $value . "\n";

}

}

else {

foreach ($_GET as $key => $value) {

$msg .= ucfirst ($key) ." : ". $value . "\n";

}

}

1.You are using code that should be placed in a area where it can be reused.

2.You are added extra complexity which isn't needed.

3.You are adding addition overhead.

4.You only go to this code on a Form post. (there's no point to the - " foreach ($_GET as $key => $value) { " here)

5.You know the values and they could be type smart - how would you validate anything?!!!

I would of done this.

<?PHP

//comment (lol don't know what a comment syntax is in PHP anymore)

//we are comming from POST, check we have an e-mail to send to.

$to = $_POST['email_to']

//if no to email

if($to == "")

{

$msg = "e-mail not supplied"

echo $msg

return //Fail

} //assign all the form values //ect... add as needed

$age = $_POST['age']

$timezone = $_POST['timezone']

$comment= $_POST['comment']

//setup Mail stuff

$subject = "Form App";

$headers = "From: Form App";

$forward = 0;

$location = "";

// this PHP I don't know.... but i guess date and time...

// this should be commented out as its never used.

$date = date ("l, F jS, Y");

$time = date ("h:i A");

//this is never used... i presume this is meant to be in the last else

// i would swop out the messages tho

$msg = "Below is the result of a form. It was submitted on $date at $time.\n\n";

//like

$msg = "Thank you for submitting the form. We will get back to you as soon as possible.";

//i would also comment out the if and remove code you are not using.

//ie do you use the forward stuff...

// if not remove the if and just have it run

//mail($to, $subject, $msg, $headers);

//echo msg;

mail($to, $subject, $msg, $headers);

if ($forward == 1) { header ("Location:$location"); }

else {

echo "Thank you for submitting the form. We will get back to you as soon as possible.";

echo msg;

}

?>

hope this helps...

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I recently tried edge. It seems a lot better. A lot of the junk in it is gone. It seems less bloated and snappy.
    • Lethal fake phone chargers are still being sold on Amazon and eBay, UK watchdog warns by Paul Hill Credit: Pexels The UK consumer rights organization, Which?, is claiming that “potentially lethal knock-off chargers” are still being sold on online marketplaces seven years after it exposed the danger of these chargers. In its latest investigation, it bought 15 USB phone chargers from several online marketplaces and found they were missing key information, meaning they cannot be legally sold in the UK. Which? bought the 15 chargers from seven online marketplaces. These were Amazon (including Amazon Haul), AliExpress, B&Q Marketplace, Debenhams Marketplace, and eBay. It said that the chargers were so badly made that anyone using them was at risk of electric shock. Over half the chargers also posed fire and explosion risks. Of the chargers purchased, one was a fake Apple USB-C 35W power adaptor charger. To confuse buyers, the box was branded with an Apple logo, but testing found it to be a fake. Further testing picked up arcing sounds after 10 seconds of use, where a current jumps between two parts of the electrical circuit, which can cause fires, explosions, or electric shock. The manufacturers of this particular charger also put modeling clay inside it to make it feel more weighty, robust, and genuine. Not all of the chargers were technically faulty; however, some were missing key packaging, markings, and documentation, meaning they can’t be sold in the UK legally. Which? said that it is now campaigning alongside a coalition of safety groups and businesses for new laws that make online marketplaces responsible for ensuring the safety of products that they choose to list on their websites. It also said the government needs to start using powers under the Product Regulation and Metrology Act, which was adopted last July, to impose safety requirements on online marketplaces via secondary legislation, but so far, there have been delays. No matter what country you are in, be sure to properly research what you are buying and only buy authentic chargers to prevent fires. You can read more about Which?’s research here.
    • Visual Studio finally gets long-awaited feature that developers will love by Usama Jawad Visual Studio Code is Microsoft's popular, lightweight, open-source code editor, it is actually Visual Studio that is the company's flagship integrated development environment (IDE). Although the IDE already offers a boatload of useful features for developers, Microsoft has finally introduced a long-requested capability that will be loved by many. While developers have already been able to create Git pull requests (PRs) directly within Visual Studio for the past couple of years, it had not been possible to review a PR without switching to the browser, until now. Microsoft revealed in December 2025 that it is working on UX that enables developers to do just that, and fast-forward to June 2026, and Visual Studio finally has native capabilities to open and inspect a PR, discuss feedback, and wrap up the review, all without switching to the browser. This integration works for both GitHub and Azure DevOps (including on-prem). Developers have access to multiple surfaces to open a PR, including Git Repository, Git Changes, and the Git menu in Visual Studio. Once you open a PR, all the important details will be immediately visible to you, from where you can navigate to various levels of granularity and branch states, depending on the reviews that you are engaged in. As you would expect, you also get a diff view that enables you to see code changes inline or side-by-side in a separate panel. You can also review commit-by-commit. Additionally, this UX fosters collaboration as you can leave comments, reply to threads, and resolve conversations easily. Naturally, you can also leverage Copilot to apply a code suggestion to fix a potential issue. When you are done, you have the ability to approve, complete, and merge the PR. This is a pretty major feature as it has been requested heavily for the past few years. You can try it out in Visual Studio 2026 version 18.7, made available here recently. Microsoft plans to enhance this experience further in future releases with comment filtering, a timeline of PR activity, and more.
    • This AdGuard Family lifetime deal is still only $15.97 by Steven Parker Today's highlighted Neowin Deal comes via our Apps + Software section, where you can get a lifetime subscription and save 90% on a lifetime AdGuard Family Plan. AdGuard is a unique program that has all the necessary features for what they claim to be "the best web experience." The software combines the an advanced ad blocker, a privacy protection module, and a parental control tool—all working in one app. This software deals with annoying ads, hides your data from a multitude of trackers, protects you from malware attacks, and even lets you restrict your kids from accessing inappropriate content. Install AdGuard and see the internet as it was supposed to be: clean and safe. Get rid of annoying banners, pop-ups & video ads once and for all Hide your data from the multitude of trackers & activity analyzers that swarm the web Avoid fraudulent and phishing website and malware attacks Protect your kids online by restricting them from accessing inappropriate & adult content Good to know Family Plan Length of access: lifetime This plan is only available to new users Redemption deadline: redeem your code within 30 days of purchase Max number of devices: 9 Access options: desktop & mobile Software version: AdGuard Family Updates included A lifetime subscription of AdGuard Family Plan normally costs $169.99, but this deal can be yours for just $15.97, that's a saving of $157.02. For full terms, specifications, and license info please click the link below. Get this AdGuard Family lifetime deal for just $15.97 (was $169.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. As an online publication, Neowin too relies on ads for operating costs and, if you use an ad blocker, we'd appreciate being whitelisted. In addition, we have an ad-free subscription for $28 a year, which is another way to show support! Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • the MCT currently downloads 26200.8653, so not completely up to date.
  • Recent Achievements

    • Week One Done
      Timaximus earned a badge
      Week One Done
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Rookie
      FBSPL went up a rank
      Rookie
    • First Post
      davidbazooked earned a badge
      First Post
    • Week One Done
      davidbazooked earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      499
    2. 2
      PsYcHoKiLLa
      175
    3. 3
      +Edouard
      160
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!