I just wrote my first PHP code or attempted to anyways. A very simple form for email submission. It's not submitting right however. Can anyone guide me towards where I'm going wrong? Thanks.
Here is the form code on this .html page
<form action="request-info.php" method="post" name="request-info">
<input name="name" type="text" value="Name">
<input name="email" type="text" value="E-mail Address">
<p>More information for</p>
<input name="family" type="radio" value="Family Member">Family
<br>
<input name="friend" type="radio" value="Friend">Friend
<br>
<input name="myself" type="radio" value="Myself">Myself
<br>
<input name="submit" type="button" value="Submit"> | <input name="reset" type="reset" value="Reset">
</form>
Here is what I have on the action page. I think this is where I may be wrong. Should I have an something in here relating to the submit button?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$family = $_POST['family'];
$friend = $_POST['friend'];
$myself = $_POST['myself'];
$to = "example@example.com";
$subject = "Information Request";
mail ($to, $subject, $info, "From: " . $name . $email);
echo "Your request has been sent!";
?>
Thanks
Change
<input name="submit" type="button" value="Submit">
to
<input name="submit" type="submit" value="Submit">
Also, you don't need a value with the submit, it's optional.
To submit, it should have a input type submit
<input name="submit" type="button" value="Submit">
In addition, for the php part to check if the mail is sent, you should do:
if(mail ($to, $subject, $info, "From: " . $name . $email)){
echo "Your request has been sent!";
} else {
echo "Error";
}
Change your input type to "submit":
<input name="submit" type="submit" value="Submit">
Then on your php file, I see you have a variable $info
...
mail ($to, $subject, $info, "From: " . $name . $email);
But I don't see that it's actually defined anywhere. Before your mail function, give $info
a value.
$info = "Hello World!";
Make sure to upload these files to a server - the php won't execute locally (unless you have a localhost running).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.