Hi, here's some php self code that when you enter something into a form field, it echo's on the same web page, while showing the same form over and over again. You can paste it into notepad to see how cool it works. I need to have the form fields, also send to an email at the same time. Can someone tell me how? Thank you very much. <?php if($_POST['text']=="") { ?><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> <?php } else { echo $_POST['text']; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> <?php } ?> Usual email form that I need the above fields to send to as well at the same time. Not sure how to list it on the page so the email will work. Thank you very much. <?php $mailto = 'email@website.com'; $sendfield = $_POST['text']; $subject = 'Email subject'; $from = "From: '$sendfield'" . "\n" . $messageproper = 'Field sent to this email: $sendfield\n'; mail('$mailto','subject',$messageproper,$from); ?>
Hope this code helps you. <?php if(empty($_POST['submit'])) { echo stripslashes($_POST['text']); } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> Code (markup): Demo : http://tanfwc.net/testing/demo1.php
Here's the email code you wanted to be added. This is not a safe email form. You must add some checks before taking it live on the web. <?php if($_POST['text']=="") { print ' <form method="post" action=""> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> '; } else { echo $_POST['text']; $mailto = 'email@website.com'; $sendfield = $_POST['text']; $subject = 'Email subject'; $from = "From: ".$sendfield. "\n" ; $messageproper = 'Field sent to this email: $sendfield\n'; mail($mailto,$subject,$messageproper,$from); print ' <form method="post" action=""> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> '; } ?>
Wow Jeet very, good but I don't understand how it works. How does everything appear on the same page without the PHP SELF? And a minor problem, this is showing in the email instead of the text entered and not sure why. Field sent to this email: $sendfield Please get back to me, Id really like to know how this is working. Thanks
Change the message line to the below in the above code. $messageproper = 'Field sent to this email: '.$sendfield.'\n'; About your other question, notice the <form action="" part? That means to submit the form to the same page/script. You can Post the form to another page or to the same page for processing. Bye
That is sure great, cuts out all that PHP SELF stuff, who knew! I added the code underneath the following, gathering a field from my sql. When I do it send 5 fields to my email instead of just one. Can anyone see why its duplicating 5 times instead of just once? Thank you very much.
I think this is the problem, change this: $query = "SELECT websitename FROM getfield WHERE websitename = '$modify'"; PHP: to this: $query = "SELECT DISTINCT websitename FROM getfield WHERE websitename = '$modify'"; PHP: - Andy