PHP Email Form Not Sending Input Text [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am trying to create an event registration form for my event (my first time using PHP), but am having trouble with the input text for my HTML/PHP form. I can submit the form and it sends me an email with the names of the inputs, but not the actual entered text/information.
Here is my HTML code:
<div class="WMF-form">
<form method="post" action="myform.php">
Name: <input type="text" name="name">
E-mail: <input type="text" name="email">
Family Count: <textarea name="familycount" rows="5" cols="40"></textarea>
Family Names:: <textarea name="familynames" rows="5" cols="40"></textarea>
Volunteer:
<input type="radio" name="volunteer" value="female">Female
<input type="radio" name="volunteer" value="male">Male
<input type="radio" name="volunteer" value="other">Other
Fee Options:
<input type="radio" name="feeoptions" value="female">Female
<input type="radio" name="feeoptions" value="male">Male
<input type="radio" name="feeoptions" value="other">Other
Lodging:
<input type="radio" name="lodging" value="female">Female
<input type="radio" name="lodging" value="male">Male
<input type="radio" name="lodging" value="other">Other
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</section>
Here is my PHP code:
PHP code
PHP code

PHP $_POST values are case sensitive. Your HTML has
<input type="text" name="name">
But you access it in the PHP file as
$Name = $_POST["Name"];
Make sure the cases match.
Try
$Name = $_POST["name"];

Capitalize your names in your form. the post variables have a capital Name Email FamilyNames etc and the form doesnt

Related

Inserting multiple rows from multiple question radio form in PHP

I have a form to determine the user's personality. So each question (there are 25) has 4 possible answers to choose from:
<form method="post">
<div>
<label for="name"></label>
<input name="name" id="name" placeholder="Name">
</div>
<div>
<label for="surname"></label>
<input name="surname" id="surname" placeholder="Surname">
</div>
<br>
<div>
<label for="q1">Question 1</label><br>
<input type="radio" name="q1" id="q1" value="S"> q1c1 <br>
<input type="radio" name="q1" id="q1" value="D"> q1c2 <br>
<input type="radio" name="q1" id="q1" value="K"> q1c3 <br>
<input type="radio" name="q1" id="q1" value="I"> q1c4 <br>
</div>
<br>
<div>
<label for="q2">Question 2</label><br>
<input type="radio" name="q2" id="q2" value="D"> q2c1 <br>
<input type="radio" name="q2" id="q2" value="K"> q2c2 <br>
<input type="radio" name="q2" id="q2" value="I"> q2c3 <br>
<input type="radio" name="q2" id="q2" value="S"> q2c4 <br>
</div>
<br>
<div>
<label for="q3">Question 3</label><br>
<input type="radio" name="q3" id="q3" value="S"> q3c1 <br>
<input type="radio" name="q3" id="q3" value="I"> q3c2 <br>
<input type="radio" name="q3" id="q3" value="D"> q3c3 <br>
<input type="radio" name="q3" id="q3" value="K"> q3c4 <br>
</div>
<br><br>
<button>Submit</button>
</form>
I need to insert the name, surname, and the selection of the question in one line. The next row in the database should also contain the name, surname, and then the next question's selection for all 25 questions.
My table users in the database only has 3 columns namely: name, surname, q
I am very new to PHP and tried some previous questions but none worked for my particular scenario.
I assume you are working fully with PHP, so no JavaScript or Ajax involved.
first of all you need to specify where your request should send:
<form method="post" action="https://example.org/target.php">
in target.php, you need to read data out of $_POST. In your case, it must be something like $_POST['name'].
From there on, you can do whatever you want with the data.
Please consider this answer as a minimal question as you need to do further checks, such as security checks, prevent SQL injections and overall data validation.

HTML into a text file using PHP

I am trying to get this information into a text file using PHP.
All of the websites that I have looked at only really cover entering a first and a last name had having the information echoed.
I was wondering if anyone has a suggestion on how to do this? That would be very helpful.
<form action="action.php" method="post" />
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="question" value="yes" checked> Yes<br>
<input type="radio" name="question" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
form action="action.php" method="post" />
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="question" value="yes" checked> Yes<br>
<input type="radio" name="question" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
<input type="checkbox" name="tool" value="Control">Control Systems Toolbox<br>
<input type="checkbox" name="tool" value="Image">Image Processing Toolbox<br>
<input type="checkbox" name="tool" value="Optimiz">Optimization Toolbox<br>
<input type="checkbox" name="tool" value="Robust">Robust Control Toolbox<br>
<input type="checkbox" name="tool" value="Signal">Signal Processing Toolbox<br>
Please enter a comma separated list of toolboxes you would like to use for you$
<input type="text" name="textquestion" value=""><br>
<input type="submit" value="Submit">
This is fairly straightforward,
$file = "myfile.txt";
if (isset($_POST['question']) && isset($_POST['tool'])) {
$fh = fopen($file, 'a');
$text = $_POST['question']. ' ' .$_POST['tool'];
fwrite($fh,$text); // Write form data to the file
fclose($fh); // Close the file
}
This would be put in your action.php file, and would write to a file in the same directory.
Also a caveat, you have input names that aren't unique, so you would want to add a third field to this. 'question' should be a unique name as you're using it when posting data.

html form entry data to my email [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have a form on my website for people to fill out and I just want the information to be sent to me in an email when they press the submit button but i'm struggling with the PHP for it.
below is the form I have
<form action="senddata.php">
<label for="fullname"> full name:</label><br>
<input type="text" name="fullname" id="fullname"><br><br>
<label for="psn">PSN</label><br>
<input type="text" name="psn" id="psn"><br>
<label for="email">Email:</label><br>
<input type="text" name="email" id="email"><br>
<label for="contact"> Contact number</label><br>
<input type="text" name="contact" id="contact"><br>
<label for="team">Team supported</label><br>
<input type="text" name="team" id="team"><br>
<input type="submit" value="SUBMIT FORM">
</form>
This is how you should implement this.
<?php
if(isset($_POST['submit']))
{
$msg = "Full Name:".$_POST['fullname']."\n PSN:".$_POST['psn']."\n Email:".$_POST['email']."\n contact:".$_POST['contact']."\n Team:".$_POST['team'];
$msg = wordwrap($msg,70);
$header = 'From: yourmail#yourmail.com>' . "\n";
// send email
mail("'".$_POST['email']."'","Your mail subject goes here",$msg,$header);
}
?>
<form action="senddata.php" method="post">
<label for="fullname"> full name:</label><br>
<input type="text" name="fullname" id="fullname"><br><br>
<label for="psn">PSN</label><br>
<input type="text" name="psn" id="psn"><br>
<label for="email">Email:</label><br>
<input type="text" name="email" id="email"><br>
<label for="contact"> Contact number</label><br>
<input type="text" name="contact" id="contact"><br>
<label for="team">Team supported</label><br>
<input type="text" name="team" id="team"><br>
<input type="submit" name="submit" value="SUBMIT FORM">
</form>
you should add method for send your data. method="post"and you should use a name for your submit button to check whether your form is submitted or notname="submit"
refer this: php.net

HTML Form - PHP Email with custom messages and tickbox

I have a HTML form with radio buttons, option boxes (drop down boxes), checkboxes, text fields and so on. I have the form pointed to another file called send.php to email the form on but how would I do this with the tickboxes and radio buttons and input text in between each answer? I would kind of like to format it like this:
Welcome: {name}
Your age group it between: {radio button with age groups}
And so on. I can't give you the actual code as it is private but I can give this instead which uses the kind of code 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>
Sorry it's so random. I ran out of ideas! Also sorry for my coding abilities, I don't normally do HTML!
Thanks.
I'm hoping this will help...if I'm understanding your question correctly.
Make sure to add a method to your form tag. For example:
<form action="send.php" method="post">. In send.php, you want to grab your variables by name attribute, for example:
$name = $_POST['Name'];
$ageGroup = $_POST['AgeGroup'];
And then you want to build out your email. PHP allows variables to be parsed in double quote strings, which can help you build your message the way you want it. (Reference)
$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 just a simple example, but this might be able to get you started.
you need to add method="POST" attribute to tag.
then, in send.php to read values, for example 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 info go to manual: http://php.net/manual/en/reserved.variables.post.php
This way you can group the radio buttons into one name, and you can get the values in the 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>

PHP error - Inserting a user form into a database

I'm getting a strange error when I try to submit user-generated data to a database via PHP commands. When I hit the submit button below, instead of the PHP page running its' function I am presented with a display of the raw code on my browser. I have a command at the bottom of my HTML page that looks like this:
<form action="insert.php" method="post">
<input type="submit">
</form>
So that when the user hits the submit button, the PHP file insert.php (detailed below) is called to input the answers onto a database, separating each answer into it's own field.
Here is the code I'm working with:
<?php
$con=mysqli_connect("host","username","password","database");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
Right now, the questions are in a and not a (is there a functional difference in this case?). They look like:
<form class="testAns" id="widthAns">
<input type="radio" name="answer" value="skinny">-25%
<input type="radio" name="answer" value="skinny">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="fat">+10%
<input type="radio" name="answer" value="fat">+25%
</form>
<form class="testAns" id="spaceAns">
<input type="radio" name="answer" value="small">-25%
<input type="radio" name="answer" value="small">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="wide">+10%
<input type="radio" name="answer" value="wide">+25%
</form>
<form class="testAns" id="weightAns">
<input type="radio" name="wanswer" value="light">-25%
<input type="radio" name="answer" value="light">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="heavy">+10%
<input type="radio" name="answer" value="heavy">+25%
</form>
<form method="post" action="insert.php" class="testAns" id="heightAns">
<input type="radio" name="answer" value="short">-25%
<input type="radio" name="answer" value="short">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="tall">+10%
<input type="radio" name="answer" value="tall">+25%
</form>
The important part is for the "value" associated with each button to be logged into the database. For example, if a user selects "+10%" I want be able to log the word "heavy".And then there are two text input fields:
<form id="intro">
City: <input type="text" name="answer"><br>
Why you are using this tool:<input type="text" name="answer">
</form>
So for these text fields I need the user input logged as the answer.
I see you got the PHP thing fixed.
Now you need to fill your form with data. This:
<form action="insert.php" method="post">
<input type="submit">
</form>
sends only the submit value. You need to add input fields inside that form tag, otherwise, nothing else will get sent. So, since you're sending an answer array, you should add those (adding them as text fields, as an example):
<form action="insert.php" method="post">
<input type="text" name="answer[]" />
<input type="text" name="answer[]" />
etc...
<input type="submit" />
</form>
And make sure you filter all user inputs before writing anything into the database, as otherwise my buddy Bobby Tables might come to visit you.
Make sure in your XAMPP Control Panel that Apache and MySQL are running. Then check if your input fields are inside the <form action='insert.php' method='POST'> input fields </form>
Your HTML code would look like this:
<html>
<body>
<form action='insert.php' method='POST'>
<table>
<tr><td>Width: </td><td>
<input type="radio" name="width" value="skinny">-25%
<input type="radio" name="width" value="skinny">-10%
<input type="radio" name="width" value="mid">normal
<input type="radio" name="width" value="fat">+10%
<input type="radio" name="width" value="fat">+25%
</td></tr>
<tr><td>Spacing: </td><td>
<input type="radio" name="spacing" value="small">-25%
<input type="radio" name="spacing" value="small">-10%
<input type="radio" name="spacing" value="mid">normal
<input type="radio" name="spacing" value="wide">+10%
<input type="radio" name="spacing" value="wide">+25%
</td></tr>
<tr><td>Weight: </td><td>
<input type="radio" name="weight" value="light">-25%
<input type="radio" name="weight" value="light">-10%
<input type="radio" name="weight" value="mid">normal
<input type="radio" name="weight" value="heavy">+10%
<input type="radio" name="weight" value="heavy">+25%
</td></tr>
<tr><td>Height: </td><td>
<input type="radio" name="height" value="short">-25%
<input type="radio" name="height" value="short">-10%
<input type="radio" name="height" value="mid">normal
<input type="radio" name="height" value="tall">+10%
<input type="radio" name="height" value="tall">+25%
</td></tr>
<tr><td>City: </td><td><input type="text" name="city"></td></tr>
<tr><td>Why you are using this tool: </td><td><input type="text" name="tool"></td></tr>
<tr><td></td><td><input type='submit'></td></tr>
</table>
</form>
</body>
</html>
What are you using in creating your php files? Dreamweaver? Notepad? Try this: SAVE AS your file, Save As Type: All Files and name it insert.php.
<?php
$con=mysqli_connect("localhost","YourUsername","YourPassword(if any)","NameOfYourDatabase");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$width=$_POST['width'];
$spacing=$_POST['spacing'];
$weight=$_POST['weight'];
$height=$_POST['height'];
$city=mysqli_real_escape_string($con,$_POST['city']);
$tool=mysqli_real_escape_string($con,$_POST['tool']);
/* REAL ESCAPE STRING WOULD PREVENT A BIT OF SQL INJECTION */
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$city','$tool','$width','$height','$spacing','$weight')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>

Categories