@NogDogOct 07.2004 — #Following is the code I use, stripped down a bit and modified to protect the innocent - or at least me. [code=php] <html> <head><title>Email</title></head> <body> <?php echo "<h1>Email Me</h1>n"; # send the mail if(isset($send)) { if(strlen($subject) > 0 and strlen($message) > 0 and strlen($addy) > 0) { # note: $address comes from include: include "email/email.txt"; # fictional file name for this example $result = mail($address, $subject, $message, "From: $addynReply-To: $addy"); if($result) { echo "<h2>Message Sent</h2>n"; echo "<p><a href=index.php>Return to home page.</a></p>n"; } else { echo "<h2>ERROR: Message Not Sent</h2>n"; echo "<p>PHP returned the following error: $result</p>n"; echo "<p><a href=index.php>Return to home page.</a></p>n"; } } else { echo "<h2>ERROR: All Fields Are Required</h2>n"; echo "<p><a href=mail.php>Try again</a>.n"; } } # display the form else { echo "<form action=mail.php>n"; echo "<p>Your email address: "; echo "<input type=text size=30 maxlength=50 name=addy></p>n"; echo "<p>Message subject: "; echo "<input type=text size=50 maxlength=70 name=subject></p>n"; echo "<p>Message:<br>n"; echo "<textarea name=message cols=55 rows=10></textarea>n"; echo "<p><input type=submit value='Send Message'>"; # the next hidden field is what lets page know you are sending mail: echo "<input type=hidden name=send value=1></p>n"; echo "</form>n"; } ?> </body> </html> [/code] The file "email.txt" would simply need to include a line like this: [code=php] <?php $address = "[email protected]"; ?> [/code]
@NogDogOct 09.2004 — #[i]Originally posted by RedLooney [/i]
[B]Thanks NogDog. That was a big help, only shouldn't the email.txt file be email.php? [/B][/QUOTE] No, it doesn't really matter what you call it. The PHP processor is already running for your main file, so at that point it just reads in the text from the included file and processes it.
BTW, the whole reason I do that is so that I can have the file with my email address in a less-accessible directory, adding to the privacy aspect.
@RedLooneyauthorOct 09.2004 — #Thank you very much Nog. It works like a charm.
I finally got a couple of books on PHP and MySQL today, so (hopefully) after reading through them, I'll be proficient with both. It doesn't seem awfully complicated, but I suppose I'll find out.