/    Sign up×
Community /Pin to ProfileBookmark

Simple PHP Contact Form

I’m new to PHP and have just created a contact form. I’d like to add additional fields that are included in the email.

I put the fields into the html – there are 8 in total. I just don’t know how to create the php to display the additional info.

[B]Here is the Form:
[/B]

[code=html]<form onSubmit=”return checkForm();” method=post action=”sendmail.php”>
Name: <input name=”name” type=”text” size=”40″ value=”” id=name>
Organization: <input name=”org” type=”text” size=”40″ value=”” id=org>
City: <input name=”city” type=”text” size=”20″ value=”” id=city>
State: <input name=”org” type=”text” size=”5″ value=”” id=org>
Zip: <input name=”zip” type=”text” size=”8″ value=”” id=zip>
Phone: <input name=”phone” type=text value=”” id=phone>
Email: <input name=”email” type=text value=”” id=email>
Message: <textarea name=”message” type=text value=”” id=message rows=”8″ cols=”40″></textarea>
</form>[/code]

I think the way I’m doing it only allows for 4 parameters to send in the email(my email address, the email subject, the message, and the from-email address.) How would I make it so that the $message contains ‘message’ ‘phone’ ‘city’ ‘state’ etc? (from the form)

[B]This is the PHP (sendmail.php):[/B]

[code=php]<?php
$email = $_REQUEST[’email’] ;
$message = $_REQUEST[‘message’] ;

mail( “[email protected]”, “Email Subject”,
“$message”, “From: $email”);
header( “Location:contact_thanks.php” );
?>[/code]

Any help is much appreciated, thanks!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DaiLaughingJul 21.2009 — You need to add to the second and third lines in the same way but for the other form INPUT names. That will give you variables containing the other values you have added to the form.

Then you could do an extra line something like:

[code=php]$message="$message (additional info: city: $city state: $state)";[/code]

and so on. This goes before the mail send line.

The variables will just be added to the end of the message in the email. How you lay it out is up to you but you might want to use new lines and tabs as well.
×

Success!

Help @talkingAnimals 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.17,
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,
)...