Jump to content

Send off a message code book example problem


Html

Recommended Posts

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 by Html
Link to comment
Share on other sites

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

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 by Html
How can this work for contacting an administrator
Link to comment
Share on other sites

 <?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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...