There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Web Form with php sendmail


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
22-Feb-2006, 06:50 PM #1
Question Web Form with php sendmail
Hi I am wondering if anyone can offer some simple advice, I have started to work in my first php script submitting a website form via email and I am trying to use php, now I can get an email sent to me with 90% of the data in but I cannot work out how to include more than one checkbox result.

I have included sample site code and the php code i am using -
For the arrays -

PHP Code:
<form name="form1" method="post" action="sendmail.php">

<
input name="awards[]" type="checkbox" id="awards[]" value="award1">
<
input name="awards[]" type="checkbox" id="awards[]" value="award2">
<
input name="awards[]" type="checkbox" id="awards[]" value="award3"
PHP Code:
<?php
$firstname 
$_REQUEST['firstname'];
$secondname $_REQUEST['secondname'];
$nickname $_REQUEST['nickname'];
$emailadd $_REQUEST['emailadd'];
$prefcontact $_REQUEST['prefcontact'];
$mobileno $_REQUEST['mobileno'];
$homeno $_REQUEST['homeno'];
$homeaddress $_REQUEST['homeaddress'];
$homepostcode $_REQUEST['homepostcode'];
$awards $_REQUEST['awards[]'];
$capitation $_REQUEST['capitation'];
$message "The Feedback Form
From: $email
First Name: $firstname
Second Name: $secondname
Nick Name: $nickname
Email Address: $emailadd, 
Prefered Contact Method: $prefcontact
Mobile Number: $mobileno 
Home Number: $homeno
Home Address= $homeaddress
Home Postcode: $homepostcode
Awards: $awards


mail( "
email@address.com", "Join Us . . .", $message, "From:" $email, "mail.address.com" );
?>
Also i know its not an easy job, but am i going about this the right way and would it be possible to find out the best way to tidy the code up.

Thanks Again
Chris Rutter
__________________
"Some day a computer intelligence will arrise that is capable of being aware of the entirety of human thought and expression stored on the web.. and it will be completely useless because no one will be able to get it to stop laughing."
John L Williams
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
22-Feb-2006, 06:52 PM #2
Your checkboxes need to have unique names.
Also, you don't have to write out each form field in the script like that
See: http://webdevfaqs.com/php.php#mailer
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
22-Feb-2006, 06:59 PM #3
ok brilliant, I was under the impression that I could use the [] after the name to indicate it was an array and could some how just submit the array?

Thanks
Chris
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
22-Feb-2006, 07:02 PM #4
You can use it that way.
$awards = serialize($_REQUEST['awards']);
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
22-Feb-2006, 07:12 PM #5
im sorry im a bit lost by all this really need to sit down and look at php properly, but where abouts would the $awards = serialize($_REQUEST['awards']); line go, somewhere in the mailer.php??
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
22-Feb-2006, 07:15 PM #6
Yes instead of $awards = $_REQUEST['awards[]'];

But it might be easier to just give each checkbox a unique name than going through an array of them.
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
22-Feb-2006, 07:32 PM #7
great thanks, I decided to put them in with indvidual names, one other question I do have, is that the email now comes off me@fhlinux203.fasthosts.co. uk, do you know why and is there anyway I can define whcih server send the mail?
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
22-Feb-2006, 08:04 PM #8
You want to use a different mailserver to send the email you mean?
You can change that in the php.ini file if your host allows you to. The option is called "SMTP"
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
23-Feb-2006, 07:47 AM #9
Brilliant thats all sorted, one last question and I will stop pestering you

Is there anyway to change the format of the mail it sends??
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
23-Feb-2006, 12:35 PM #10
What do you mean by the format? It will send whatever is in $message.
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
23-Feb-2006, 08:02 PM #11
sorry to pester, but I am no longer using that solution above, I should have mentioned it, I am now using that mailer.php, can I change the font, and layout of the formed result, I am prusimng not, but thought I would ask!
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
23-Feb-2006, 08:11 PM #12
You would have to send it as an HTML message
http://www.zend.com/zend/trick/html-email.php
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:01 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.