/    Sign up×
Community /Pin to ProfileBookmark

Send info to e-mail

I would like to have a page on my site where someone can fill out various fields and when they click submit the information is sent to me via e-mail.

My host supports PHP, but I am a complete beginner at server side scripting, so any help is greatly appreciated.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@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:&nbsp;";
echo "<input type=text size=30 maxlength=50 name=addy></p>n";
echo "<p>Message subject:&nbsp;";
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]
Copy linkTweet thisAlerts:
@RedLooneyauthorOct 09.2004 — Thanks NogDog. That was a big help, only shouldn't the email.txt file be email.php?
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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.
×

Success!

Help @RedLooney spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...