HTML Form - PHP Email with Custom Messages and Tickbox

I have an HTML form with radio buttons, option fields (dropdowns), checkboxes, text boxes, etc. I have a form pointing to another file called send.php in order to submit the form via email, but how would I do this with a tickbox and radio buttons and typing text between each response? I would like to format it like this:

Welcome: {name} In your age group, this is: {switch with age groups}

Etc. I cannot give you the actual code as it is private, but I can give this instead using the code type and format:

<form action="send.php">

<input type="radio" name="AgeGroup" value="AgeGroup1"> 0-18<br>
<input type="radio" name="AgeGroup" value="AgeGroup2"> 19-29<br>
<input type="radio" name="period" value="AgeGroup3"> 30-39<br>
<input type="radio" name="period" value="AgeGroup4"> 40-49<br>
<input type="radio" name="period" value="AgeGroup5"> 50+<br>

<br><br><br><br>

<select name="Country">
  <option value ="UK">United Kingdom</option>
  <option value ="USA">United States</option>

</option></select>

<br><br><br><br>

<input type="text" name="PostCode" size="5">

<br><br><br><br>

<input type="text" name="HouseNumber" size="5">

<br><br><br><br>

<textarea id="Family" class="input" name="FamilyNumber" rows="10" cols="60"></textarea>

<br><br><br><br>

<input type="checkbox" name="Delievery" value="NextDay"> Next Day Delievery
<br>
<input type="checkbox" name="Delievery" value="TwoToFive"> 2-5 Day
<br>
<input type="checkbox" name="Outcome" value="Dismissed"> Dismissed

<br><br><br><br><br><br>

<center><button id="Send" type="submit" style="height:25px; width:100px; background-color: grey">Send</button></center>

</form>
      

Run codeHide result


Sorry, this is so random. I'm out of ideas! Also sorry for my coding skills, I don't usually do HTML!

Thank.

+3


source to share


3 answers


I hope this helps ... if I understand your question correctly.

Make sure to add the method to your form tag. For example:    <form action="send.php" method="post">

. In send.php you want to capture variables by name attribute, for example:

$name = $_POST['Name'];
$ageGroup = $_POST['AgeGroup'];

      



And then you want to create your email. PHP allows you to parse variables in double quote strings, which can help you build your message the way you want. ( Link )

$to = "person@example.com";
$subject = "Subject goes here";
$message = "Welcome: $name. Your age group is between: $ageGroup";

//note: headers are optional
$headers = "From: you@example.com" . "\r\n" . "CC: anotherperson@example.com";

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

      

This is a simple example, but it might get you started.

0


source


you need to add the tag method = "POST" .

then in send.php to read values ​​like PostCode or HouseNumber:

echo "Post code: ".$_POST["PostCode"]."<br />";
echo "House number: "$_POST["HouseNumber"]";

      



for age:

if(isset($_POST["AgeGroup"]) {
    echo "Age group: ".$_POST["AgeGroup"];
}
if(isset($_POST["period"]) {
    echo "Age group: ".$_POST["period"];
}

      

for more information go to the manual: http://php.net/manual/en/reserved.variables.post.php

0


source


This way you can group radio buttons into one name and you can get the values ​​in php as $_POST['name']

<form action="send.php" method="post">

<input type="radio" name="AgeGroup" value="0-18"> 0-18<br>
<input type="radio" name="AgeGroup" value="19-29"> 19-29<br>
<input type="radio" name="AgeGroup" value="30-39"> 30-39<br>
<input type="radio" name="AgeGroup" value="40-49"> 40-49<br>
<input type="radio" name="AgeGroup" value="50+"> 50+<br>

<select name="Country">
  <option value ="UK">United Kingdom</option>
  <option value ="USA">United States</option>
</option></select>

<input type="text" name="PostCode" size="5">

<input type="text" name="HouseNumber" size="5">

<textarea id="Family" class="input" name="FamilyNumber" rows="10" cols="60"></textarea>

<input type="checkbox" name="Delievery" value="NextDay"> Next Day Delievery
<br>
<input type="checkbox" name="Delievery" value="TwoToFive"> 2-5 Day
<br>
<input type="checkbox" name="Outcome" value="Dismissed"> Dismissed

<center><button id="Send" type="submit" style="height:25px; width:100px; background-color: grey">Send</button></center>

</form>
      

Run codeHide result


0


source







All Articles