Html Posted February 9, 2019 Share Posted February 9, 2019 (edited) Hi, I have tried an example from Php 7 in easy steps book. I don't understand how this code is suppose to work, it didn't quite work for me as demonstrated in the chapter of this book. <form action="action_handler.php" method="POST"> <dl> <dt>Name: <dd><input type="text name="name"> <dt>Email Address: <dd><input type="text name="mail"> <dt>Your Message: <dd><textarea rows="10" cols="20" name="comment"> </textarea> </dl> <p><input type="submit" value="Submit"></p> </form> That was the result after it goes to action_handler.php Quote Thanks for this comment ... hello test We will reply to So below is the code, it is an odd example, I assumed it would contain some kind of send off to an address. <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP Form Handler</title> </head> <body> <?php $name = $_POST['name'] ; $mail = $_POST['mail'] ; $comment = $_POST['comment'] ; echo "<p>Thanks for this comment $name ...</p>" ; echo "<p><i>$comment</i></p>" ; echo "<p>We will reply to $mail</p>" ; ?> </body> </html> Thank you. Edited February 9, 2019 by Html Link to comment Share on other sites More sharing options...
Ingolme Posted February 10, 2019 Share Posted February 10, 2019 You forgot to close the quotation marks here: type="text name="name" Link to comment Share on other sites More sharing options...
Html Posted February 10, 2019 Author Share Posted February 10, 2019 I copied it exactly as the chapter states. Is identical to what is there. Link to comment Share on other sites More sharing options...
dsonesuk Posted February 10, 2019 Share Posted February 10, 2019 So they got right! The source code you can download, <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP Form Action</title> </head> <body> <form action="action_handler.php" method="POST"> <dl> <dt>Name:<dd><input type="text" name="name"> <dt>Email Address:<dd><input type="text" name="mail"> <dt>Comments:<dd><textarea name="comment" rows="5" cols="20"></textarea> </dl> <p><input type="submit" ></p> </form> </body> </html> but got it wrong in the book? how embarrassing. You know what! I would sue, but just in case, I would recheck in case they counter sue on the grounds you are at fault in that you mistakenly missed out the quotes. Link to comment Share on other sites More sharing options...
Html Posted February 10, 2019 Author Share Posted February 10, 2019 (edited) The book is correct, when I did this yesterday, I left out the "" for text alone, who knows why I typed it that way. text name wasn't correct. With that example, just how does a message get sent to an email of a web page administrator? Edited February 10, 2019 by Html How can this work for contacting an administrator Link to comment Share on other sites More sharing options...
justsomeguy Posted February 11, 2019 Share Posted February 11, 2019 It doesn't, that code does not send an email. It just prints what was submitted. Link to comment Share on other sites More sharing options...
Html Posted February 11, 2019 Author Share Posted February 11, 2019 I thought that was the purpose of that example in the book. Can it be modified to do that then? I guess it can, what do I need to do? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 11, 2019 Share Posted February 11, 2019 There are several ways to send email. The most basic is the built-in mail function, but classes like PHPMailer are more useful. Link to comment Share on other sites More sharing options...
Html Posted February 11, 2019 Author Share Posted February 11, 2019 Right well the example above is fine, I just want to get that to actually send off a message to an email address. Link to comment Share on other sites More sharing options...
Ingolme Posted February 12, 2019 Share Posted February 12, 2019 I would guess that your book explains how to send mail in a later chapter, but if your book does not have it, you can find the mail function in the W3Schools reference https://www.w3schools.com/php7/func_mail_mail.asp Link to comment Share on other sites More sharing options...
Html Posted February 12, 2019 Author Share Posted February 12, 2019 I only have one of the books, and there is no chapter on sending email from a form or message to an address. Link to comment Share on other sites More sharing options...
Html Posted February 12, 2019 Author Share Posted February 12, 2019 <?php // the message $msg = "First line of text\nSecond line of text"; // use wordwrap() if lines are longer than 70 characters $msg = wordwrap($msg,70); // send email mail("someone@example.com","My subject",$msg); ?> And what exactly is this? How could that work with what I have above, or it wouldn't work. Link to comment Share on other sites More sharing options...
Ingolme Posted February 12, 2019 Share Posted February 12, 2019 That is just an example, you should actually read the paragraphs on the page which describe the mail function to understand how it works. Pass your form data into the arguments of the mail() function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now