Jump to content
Html

Send off a message code book example problem

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

Share this post


Link to post
Share on other sites

You forgot to close the quotation marks here:

type="text name="name"

Share this post


Link to post
Share on other sites

I copied it exactly as the chapter states. Is identical to what is there.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

It doesn't, that code does not send an email.  It just prints what was submitted.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

There are several ways to send email.  The most basic is the built-in mail function, but classes like PHPMailer are more useful.

Share this post


Link to post
Share on other sites

Right well the example above is fine, I just want to get that to actually send off a message to an email address.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

I only have one of the books, and there is no chapter on sending email from a form or message to an address.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...