hey
how do i get my submit button to work? i want people to fill in the guestbook and then click submit and have it send to kate@mahler.x10hosting.com
this is the link http://mahler.x10hosting.com/katemahler/guestbook.html
thanks
hey
how do i get my submit button to work? i want people to fill in the guestbook and then click submit and have it send to kate@mahler.x10hosting.com
this is the link http://mahler.x10hosting.com/katemahler/guestbook.html
thanks
There's no way to do this in one step, what you'll have to do is send the user input to a php page that then sends the mail.
And you're missing form tags...
replace
with the following:HTML Code:<table width="575" border="0" cellpadding="3" cellspacing="2"> <tr> <td width="250"><div align="right"><span class="style6">Name:</span></div></td> <td width="307"><label> <input name="Name" type="text" id="Name" size="35" maxlength="80"> </label></td> </tr> <tr> <td><div align="right"><span class="style6">E-mail:</span></div></td> <td><input name="e-mail" type="text" id="e-mail" size="35" maxlength="80"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><div align="right"><span class="style6">What was your favorite part ? </span></div></td> <td><label> <select name="favorite" id="favorite"> <option value="pictures">Pictures</option> <option value="Bio">Bio</option> <option value="school">School</option> <option value="trips">Trips</option> </select> </label></td> </tr> <tr> <td><div align="right"><span class="style6">Any comments? </span> </div></td> <td><label> <textarea name="comments" cols="35" rows="4" id="comments"></textarea> </label></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><input name="email" type="hidden" id="email" value="kate@mahler.x10hosting.com"></td> <td><label> <input type="submit" name="Submit" value="Submit"> </label> <label></label></td> </tr> </table>
And add a new file "guestbookmail.php" with the following content:HTML Code:<form action="guestbookmail.php" method="post"> <table width="575" border="0" cellpadding="3" cellspacing="2"> <tr> <td width="250"><div align="right"><span class="style6">Name:</span></div></td> <td width="307"><label> <input name="Name" type="text" id="Name" size="35" maxlength="80"> </label></td> </tr> <tr> <td><div align="right"><span class="style6">E-mail:</span></div></td> <td><input name="e-mail" type="text" id="e-mail" size="35" maxlength="80"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><div align="right"><span class="style6">What was your favorite part ? </span></div></td> <td><label> <select name="favorite" id="favorite"> <option value="pictures">Pictures</option> <option value="Bio">Bio</option> <option value="school">School</option> <option value="trips">Trips</option> </select> </label></td> </tr> <tr> <td><div align="right"><span class="style6">Any comments? </span> </div></td> <td><label> <textarea name="comments" cols="35" rows="4" id="comments"></textarea> </label></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><input name="email" type="hidden" id="email" value="kate@mahler.x10hosting.com"></td> <td><label> <input type="submit" name="Submit" value="Submit"> </label> <label></label></td> </tr> </table> </form>
If something doesn't work, just ask us for help again.PHP Code:<?php
$name = $_POST["Name"];
$email = $_POST["e-mail"];
$favourite = $_POST["favourite"];
$comments = $_POST["comments"];
$message = "<html><body>";
$message .= "<i>$name</i> has reacted to your site.<br>";
$message .= "Favourite part: $favourite<br>";
$message .= "Comments: <br>$comments";
$message .= "</body></html>";
mail("mahlerwd <kate@mahler.x10hosting.com>","Comment in your guestbook",$message,"From: guestbook <guestbook@mahler.x10hosting.com>");
?>
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
I just see two problems with that. One, the receiver address in the html source might as well be deleted since it's hardcoded in the script. Leaving it there would only prove useful to spam bots. And two, since you're sending the message in html, you should provide the Content-type header.
Also, I think the sender address should be put in some part of the message(or else why ask for it?). It could be used for the 'From' header, however it needs to be sanitized in that case. So I'd change it a little bit to this:
HTML Code:<form action="guestbookmail.php" method="post"> <table width="575" border="0" cellpadding="3" cellspacing="2"> <tr> <td width="250"><div align="right"><span class="style6">Name:</span></div></td> <td width="307"><label> <input name="Name" type="text" id="Name" size="35" maxlength="80"> </label></td> </tr> <tr> <td><div align="right"><span class="style6">E-mail:</span></div></td> <td><input name="e-mail" type="text" id="e-mail" size="35" maxlength="80"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><div align="right"><span class="style6">What was your favorite part ? </span></div></td> <td><label> <select name="favorite" id="favorite"> <option value="pictures">Pictures</option> <option value="Bio">Bio</option> <option value="school">School</option> <option value="trips">Trips</option> </select> </label></td> </tr> <tr> <td><div align="right"><span class="style6">Any comments? </span> </div></td> <td><label> <textarea name="comments" cols="35" rows="4" id="comments"></textarea> </label></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="Submit" value="Submit"> </label> <label></label></td> </tr> </table> </form>PHP Code:<?php
$name = $_POST["Name"];
$email = $_POST["e-mail"];
$favourite = $_POST["favourite"];
$comments = $_POST["comments"];
$message = "<html><body>";
$message .= "<i>$name</i> has reacted to your site.<br>";
$message .= "Email: $email<br>";
$message .= "Favourite part: $favourite<br>";
$message .= "Comments: <br>$comments";
$message .= "</body></html>";
$headers = "From: guestbook <guestbook@mahler.x10hosting.com>\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';
mail("mahlerwd <kate@mahler.x10hosting.com>","Comment in your guestbook",$message,$headers);
?>
"But you have access to the greatest source of knowledge in the universe."
"Well I do talk to myself sometimes, yes."
"I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"
Forgetting stuff is human... Why do I keep forgetting stuff?
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
PLEASE DON'T PUT THAT ON YOUR SITE. Unless you want an SQL dump done through that code you need to add a simple function to it.
Change
toPHP Code:$name = $_POST["Name"];
$email = $_POST["e-mail"];
$favourite = $_POST["favourite"];
$comments = $_POST["comments"];
PHP Code:$name = strip_tags($_POST["Name"]);
$email = strip_tags($_POST["e-mail"]);
$favourite = strip_tags($_POST["favourite"]);
$comments = strip_tags($_POST["comments"]);
just do this:
also, just a note, i seriously suggest against using a mailto link on your page like what you have at the bottom unless you really like reading spam.PHP Code:$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$favorite = $_REQUEST['favorite'] ;
$comment = $_REQUEST['comment'] ;
$message = "$name
$favorite
$comment";
$to = "email@host.com";
$subject = "subject"
$sent = mail($to, $subject, $message);
if($sent)
{
echo "CODE IF SEND IS SUCCESSFUL";
}
else
{
echo "CODE IF SEND IS UNSUCCESSFUL";
}
Don't use kbjardmin's script. The message will all be one line and he is missing a ;
marshian's script is good if you add the strip_tags() function to the inputs.
Mind explaining how an sql dump could be achieved through that? I could see that it is possible for someone to enter somewhat harmful html, but an sql dump seems unfathomable. In fact, I think she doesn't even have a db set up. Furthermore, she's just making the page for a class which probably doesn't even touch on php, so I don't think it's necessary to include validation really. If we were to start doing that, there's a lot more we should do than strip_tags(). But there's no harm in including that function I suppose ;-)
"But you have access to the greatest source of knowledge in the universe."
"Well I do talk to myself sometimes, yes."
"I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"
So if no more faults are discovered, the code is now:
andHTML Code:<form action="guestbookmail.php" method="post"> <table width="575" border="0" cellpadding="3" cellspacing="2"> <tr> <td width="250"><div align="right"><span class="style6">Name:</span></div></td> <td width="307"><label> <input name="Name" type="text" id="Name" size="35" maxlength="80"> </label></td> </tr> <tr> <td><div align="right"><span class="style6">E-mail:</span></div></td> <td><input name="e-mail" type="text" id="e-mail" size="35" maxlength="80"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><div align="right"><span class="style6">What was your favorite part ? </span></div></td> <td><label> <select name="favorite" id="favorite"> <option value="pictures">Pictures</option> <option value="Bio">Bio</option> <option value="school">School</option> <option value="trips">Trips</option> </select> </label></td> </tr> <tr> <td><div align="right"><span class="style6">Any comments? </span> </div></td> <td><label> <textarea name="comments" cols="35" rows="4" id="comments"></textarea> </label></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="Submit" value="Submit"> </label> <label></label></td> </tr> </table> </form>
PHP Code:<?php
$name = strip_tags($_POST["Name"]);
$email = strip_tags($_POST["e-mail"]);
$favourite = strip_tags($_POST["favourite"]);
$comments = strip_tags($_POST["comments"]);
$message = "<html><body>";
$message .= "<i>$name</i> has reacted to your site.<br>";
$message .= "Email: $email<br>";
$message .= "Favourite part: $favourite<br>";
$message .= "Comments: <br>$comments";
$message .= "</body></html>";
$headers = "From: guestbook <guestbook@mahler.x10hosting.com>\r\n";
$headers .= 'Content-type: text/html; charset=utf-8';
mail("mahlerwd <kate@mahler.x10hosting.com>","Comment in your guestbook",$message,$headers);
?>
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
thank you guys this is really great.
but I'm completely new on all of this so i dont really get the php thing. i made a php page and i put that code in, and when i open it its blank. I'm sure I'm supposed to put some other stuff in, but i really just dont know what it is....i put the html code for the rest of my page on, but i dont even know if I'm supposed to put html on a php page...
more help please? sorry for the inconvenience