Hello to all it may concern, hope you’re having a great day…
I’m building a website for a clan me and a few mates have started up, and i’m trying to make a custom form due to the fact that the zyro form is limited to a certain amount of fields. So, i’m attempting to create my own form which i’ve done and i’ve styles it and what not. Now I have the issue of trying to make the form email the results to our clan email for now whilst I work on a members portal. I’ve followed steps from multiple tutorials, and none of them have worked at all. Could somebody possibly explain how this is done? I understand there are many similar topics, but none of them have an answer that works.
You can add any number of input elements (even select, textarea elements). Then you must add a uniquename attribute for each element.
action=""… empty value will tell the browser to send POST data to the current page. You can add any value for that according to your needs. (ex: action="do.php" will submit the form and send data to do.php page)
Then, you should do the backend…
<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
// if it is a post request
$name = $_POST['username']; // change username with the name attribute of your input field
// then email the result to your email
$email = 'youremail@emailhost.com'; //change this too ;)
$subject = 'I have no idea what to put as subject'; //:)
$body = 'Someone has input ' . $name;
mail($email, $subject, $body);
}
?>
Add above code to your action script. If action script is same as the page that has the form, then you should add this to the top of the page.
However, I don’t know how you need to send the email (what content). But by this way you can send a input value in email.
Wow… I had this all along earlier. I think the mistake I made, was that I made a second file and called it something then put the name of the file as the form action. That didn’t seem to work. But now it’s actually emailing me, the issue is that now it just emails the message and subject, it doesn’t actually email the result. It also has a note on the top of my page now…
Notice: Undefined index, firstname in /(filepath for page file) on line 8.
These are the two important pieces of code that would affect this I’d assume…
<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
// if it is a post request
$firstname = $_POST['firstname']; // change username with the name attribute of your input field
// then email the result to your email
$email = 'thegentlemensgaminggroup@gmail.com'; //change this too ;)
$subject = 'I have no idea what to put as subject'; //:)
$body = 'Someone has input ' . $firstname;
mail($email, $subject, $body);
}
?>
and…
First Name: <br><input class="smalltextbox" type="text" name="firstname"><br><br>
Apologies, so I figured out some more stuff but still don’t understand what you want me to change in the conditional. If I swap what’s in there for what you just sent me, it doesn’t even load the page and returns saying something else.
if ($_SERVER['REQUEST_METHOD'] === "POST") {
// if it is a post request
var_dump($_POST); exit();
$firstname = $_POST['firstname']; // change username with the name attribute of your input field
// then email the result to your email
$email = 'thegentlemensgaminggroup@gmail.com'; //change this too ;)
$subject = 'I have no idea what to put as subject'; //:)
$body = 'Someone has input ' . $firstname;
mail($email, $subject, $body);
}
?>
This way you can check whether the params are set or not.