Discussions Short Journal en>fr fr>en By spyderdc Comments: 0, member since Fri Apr 13, 2001On Fri Apr 13, 2001 02:42 AM
There seems to be a shortage of valid links at PHP Journal. Perhaps these guys could use some help developing the rest of the pages. I just happen to know of a really good PHP programmer for hire.
PHP is great for accessing databases, LDAP directories, and flat files, as well as writing dynamic HTML. I've even used it to process request approvals with email notification and cron-based reminders. Now that I know PHP, I could never give it up. The available power and flexibility are truly exhilirating! 2 Replies to Short Journal |
Need to create a form mail in PHP en>fr fr>en By naveen_shroff Comments: 0, member since Mon Jun 18, 2001On Mon Jun 18, 2001 01:31 AM
Hi Everybody,
I am new to PHP ..
I have to create a form in html and it should forward the contents in the textfield to an mail..
How do i do it in PHP ...
Please let me know...
Its urgent...
Naveen |
Final Correction to Re: Forms in PHP en>fr fr>en By spyderdc Comments: 0, member since Fri Apr 13, 2001On Mon Jun 18, 2001 07:10 AM
I think the comment form needs a review button to check one's content before posting. Hopefully 'the little elves' will pull the frst two copies of this message and only post this one:
Actually, form handling in PHP is really simple. Name the fields in your form so you can identify them in your PHP script. For example you might have: <INPUT TYPE="text" NAME="FirstName">
Then, set your form to post to a PHP script. This should look like: <FORM NAME="FirstForm" METHOD="post" ACTION="backend.php">
Now, in your PHP script, 'backend.php' in the example above, use the field names as variables. You can manipulate the data from the form just about any way you want. Store it in a database, display it on the screen, or email it to someone. Here's a short example that will display on screen and send an email:
<HTML>
<HEAD>
<TITLE>Form Response</TITLE>
</HEAD>
<BODY>
<?php
echo "<B>The first name you entered is:</B> $FirstName<BR>\n";
echo "<B>The last name you entered is:</B> $LastName<BR>\n"
$To = "johndoe@whatever.com"
$Subject = "Form Content";
$Message = "The first name is: $FirstName<BR>\n" .
"The last name is: $LastName<BR>\n";
$Headers = "From: My Name <myname@somewhere.com>\n" .
"X-Sender: <myname@somewhere.com>\n" .
"X-Mailer: $PHP_SELF\n" .
"Content-Type: text/html; charset=iso-8859-1\n";
mail($To, $Subject, $Message, $Headers);
?>
</BODY>
</HTML>
Play with this a little bit, you should find it really simple to work with. For testing, make the emails send to your own address and study the content. Also, you might test the return value of the mail function to make sure it sent. I usually have the HTML of the PHP page give a status message, instead of regurgitating what the user entered. So, if the mail function returns true, the page might say "Your information has been submitted, thank you.", and if it returns false, the page might say "Sorry, we could not process your information at this time, please try again".
P.S. - you can also skip the PHP and make the form's ACTION="mailto:johndoe@whatever.com". However, this does not allow you any formatting of the email contents or any control over the data being sent. It's a shortcut, and a very rudimentary one at that.
Good luck and happy coding!!
-SpyderDC |