|
|
|||||||||
|
|
Tutorial 3 - Part II -Flying into Formation - page 2O. K., so your 'submit-if' statement worked. Now the rest is easy. You want an email sent to you with your guest's input. Use this code filling in the underlined with your own personal info:
First, copy the above code. (Highlight the box and hit "edit & copy" on your browser. Then paste to notepad or another text editor.) In notepad or another text editor, change you@youremail.com to your email address and fill in the "mailfrom" variable with the name of your website. Save this altered code so you can copy it to the appropriate place in your "comment.php." Go to the top of your page of code. In your opening php code, after the opening "<?php" and the opening echo statement (echo ('<p>Form was submitted.</p>');) but before the opening "else" bracket ({), insert the above altered code. Your "comment.php" should now resemble this example: click here. Save your comment.php and load it up to your web site. Look at the comment.php in your web browser. If everything looks good, fill out the form and submit it. To see how your form should act click here. You should receive an email (at the email address you provided) with all the information you submitted in the guest comment form. If you received the email, you're done, right? Well, not exactly. (Maybe, in an ideal world, you're done, but not in my world. In my world, the party of god does the work of the devil - ruining the lives of the innocent. This is the world I live in. I can hardly consider it the 'best of all possible worlds.' I can't possibly see it as an ideal world. But if you think your world is an ideal world and, better still, if you're sure of it, then you are done. You have a form whose input will be emailed to you.) For me and others like me, however, there's still a number of things
that have to be done. But first let's review the above code. The above
code starts with a list of variables - everything that begins with the
dollar sign ($). The first variable - $date - is unnecessary because your
email comes dated. However I include this variable ($date) in case you
also want to save this information to a file somewhere. The snippet of code that your date
variable is equal to "date('F j, Y G:i:s')" is just one way of defining how you want a date to
appear. The term "stripslashes' is used
to rid your email and file of slashes that show up before quotes. "Magic_quotes_gpc" is on
by default and is the reason for these slashes. The next four
variables are input from your form. You create these variables so you
can move your guest comment input to your email. The 'refer' variable
is included so you can check to make sure the input came from your site.
The next four variables ($mailto, $mailfrom, $subject, and $body) are
used to simplify the email. They are not the only variables you could
use. You could use '$email_to' in place of '$mailto'. You could add headers. You could use
'$message' in place of '$body.' You could even use the one variable '$message' to transfer
all of your form variables to your email, like so: The periods ( . ) in the above lines are used to concatenate your sub-strings into sentences. The final line, "mail( $mailto, $subject, $body, $mailfrom or $headers)", in both email examples, gives the command to do the email. If you're fussy about the email you get and don't like seeing the word "node", you might want to add headers to the original boxed code above. That would change your code to:
(Note: In filling in the 'From' header above, use a second email address if you have one.) Now, if you also want to save this information to a file on your site, do the following:
Don't forget the final bracket ( } ). With these changes. your "comment.php" should now
look like this : click here. (If all else fails,
you can always copy this code by hitting "edit & copy" in your browser.) To test this code,
do the following: First when you get tired of receiving email,
just add two slashes ('//') one space in front of your 'mail' command line. That
will stop the email. Save your 'comment.php' again, reload to your site's
public_html, open 'comment.php' in your web browser, fill out the form
and submit it. To check to see if the code worked, open 'guests.txt.' in your browser.
You may have to hit your browser's "refresh" button, but the info you submitted should
be easily readable. If it is and you're happy with it, then go back to your 'file write'
command and place two slashes ('//') a space in front of your 'file write' command to
stop the command until you're ready to use it.
Your IP address is: 38.103.63.18 |