/    Sign up×
Community /Pin to ProfileBookmark

Please help fix PHP contact form with checkboxes

Hi,

I’ve been trying to make a simple contact form pretty much all day. I think it will probably end up being a really straightforward answer for anyone with PHP experience (I have none at all, trying to use code from a book). I am trying to achieve a simple form to collect – name, email, phone number, website, a message and to show me which services they’re interested in. Sorry my code is so messy – I’ve been going round forums trying different things and I think I’ve made it worse now! (There’s CSS with this so if you recreate might look a bit dodgy).

Currently, it does not email me the message or show which services that they have selected.

HTML:

<form action=”send_form.php” method=”POST”>
<div class=”left”><p>
<label for=”name”>Name:</label><br />
<input type=”text” name=”name” id=”name” />

<p>
<label for=”phone”>Phone:</label><br />
<input type=”text” name=”phone” id=”phone” /></p></div>

<p><br />
<label for=”email”>Email:</label>
<br />
<input type=”text” name=”email” id=”email” /></p>

<p>

<label for=”website”>Website:</label>
<br />
<input type=”text” name=”website” id=”website” /></p></div>
<div class=”bottom”>

<p>Which services do you require?</p>
<label for=”webdesign”>web design</label>
<input name=”service[]” input type=”checkbox” value=”web design”/>
<label for=”cat”>cat</label><input name=”service[]” input type=”checkbox” value=”cat” />
<br />
<label for=”hamsters”>hamsters</label><input name=”service[]” input type=”checkbox” value=”hamsters” />
<label for=”window”>window</label><input name=”service[]” input type=”checkbox” value=”window” />
<p><br />

<label for=”message”>Message:</label></p>
<p><textarea name=”message” cols=”65″ rows=”6″ name=”message”></textarea></p>
<input name=”submit” type=”submit” value=”Submit” />
</form>

PHP:

<?php
$subject =”Enquiry from Freedom Designs”;
$message=”$message”;
$name = $_POST[‘name’];
$email = $_
POST[’email’];
$phone = $_POST[‘phone’];
$website = $_
POST[‘website’];
foreach($_POST[‘service’] as $value)
{
$Body .= “Service: ” . trim(stripslashes($value)) . “n”;
}
$msg = “Item Selected:tn”;
foreach($_
POST[‘selection’] as $value)
{
$msg .= “$valuen”;
}
$recipient =’[email protected]‘;
$formcontent=” From: $namennPhone: $phonennWebsite: $websitennMessage: $message n: $service”;
$mailheader = “From: $emailrn”;
$mailheader .= “Reply-To: $emailrn”;
$mailheader .= “MIME-Version: 1.0rn”;
mail($recipient, $subject, $formcontent, $mailheader) or die(“Failure”);
echo “We’ve received your message and will reply within 24 hours.”;
?>

Would appreciate any help! Thanks ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@TecBratAug 08.2011 — This may not fix all your problems, but in a quick read-through, I noticed a problem with this block:[code=php]$msg = "Item Selected:tn";
foreach($_POST['selection'] as $value)
{
$msg .= "$valuen";
}[/code]


Looks like you have a stray "n" in the variable name.
×

Success!

Help @gemz85 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...