/    Sign up×
Community /Pin to ProfileBookmark

new at php, trying to make a form work.

Hi, I’m brand spanking new at php, and was trying to put together a contact form. It works just fine except the only info it sends is what is in the textarea “message” box”. It dosen’t send the name, phone, address, or anything. I’ve included the php which is a separate file on my site, and a sample of the html below which is on my contact page. Any help is highly appreciated. Thanks!

THE PHP:

<?php
$name = $_REQUEST[‘name’] ;
$email = $_
REQUEST[’email’] ;
$phone = $_REQUEST[‘phone’] ;
$address = $_
REQUEST[‘address’] ;

$message = $_REQUEST[‘message’] ;

mail( “[email protected]“, “Feedback Form Results”,
$message, “From: $email” );
header( “Location: http://www.set-n-me-free.com/thankyou.html” );
?>

THE HTML:

<div id=”contact”><form method=”post” action=”sendmail.php”>
<p>Name: &nbsp; <input type=”text” name=”name” value=”” size=”20″><br />
Email: &nbsp; <input type=”text” name=”from” value=”” size=”20″><br />
Phone: &nbsp; <input type=”text” name=”Phone” value=”” size=”20″><br />
Address: &nbsp; <input type=”text” name=”Address” value=”” size=”20″><br />

<textarea name=”message” rows=”15″ cols=”40″>
</textarea><br /><br />
<input type=”submit” />

</p>
</form>
</table>
</div>

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@tracknutOct 06.2009 — The body of the mail message is that third parameter in the mail() function call. All you're putting in there is your variable $message, which you've filled with the value from your "message" text area. If you want the rest of the fields in there, you need to include them. Something like:

$message = "New message from $name at tel no. $phone. He says $message";

Dave
Copy linkTweet thisAlerts:
@littlenedOct 06.2009 — To debug what's being passed to your PHP script from the form try;

<?php

echo "<pre>";

print_r($_REQUEST);

echo "</pre>";

?>

That will show you every variable coming from form.
Copy linkTweet thisAlerts:
@thraddashOct 06.2009 — As you are "posting" the data back to the webserver you should be using the $_POST superglobal.

Eg.

[CODE]$name = $_POST['name'];[/CODE]
Copy linkTweet thisAlerts:
@jefitoauthorOct 06.2009 — Thanks for the help, but I'm still confused. I tried this: $message = "New message from $name at tel no. $phone. He says $message";

but this is what I got in my email: New message from jeff at tel no. . He says test

I'm missing something here. Should I be doing separate entries like:

$message = "New message from $name";

$message = "New message from $phone"'

I don't know how to write this up. Thanks!

Thanks also for the tips on the 'echo' and the 'post' scripts!
Copy linkTweet thisAlerts:
@tracknutOct 06.2009 — I just noticed your phone variable is actually named "Phone". So you need to change your request to:

$phone = $_REQUEST['Phone'] ;

Dave
Copy linkTweet thisAlerts:
@jefitoauthorOct 06.2009 — I already have it set to 'phone'. I always thought that these variables would be included as well as the message.

<?php

$name = $_REQUEST['name'] ;

$email = $_
REQUEST['email'] ;

$phone = $_REQUEST['phone'] ;

$address = $_
REQUEST['address'] ;

$message = $_REQUEST['message'] ;
Copy linkTweet thisAlerts:
@tracknutOct 06.2009 — You have it set to "phone" (lowercase) whereas in your html you name it "Phone" (uppercase). Those are different.

Dave
Copy linkTweet thisAlerts:
@jefitoauthorOct 06.2009 — This doesn't work either. I think I need to get a book that spells it out more. Thanks anywaythough, appreciate it!
×

Success!

Help @jefito 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.30,
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,
)...