# Web Form with php sendmail



## Rutter (Dec 17, 2001)

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
$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 protected]", "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


----------



## brendandonhu (Jul 8, 2002)

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 (Dec 17, 2001)

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 (Jul 8, 2002)

You can use it that way.
$awards = serialize($_REQUEST['awards']);


----------



## Rutter (Dec 17, 2001)

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 (Jul 8, 2002)

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 (Dec 17, 2001)

great thanks, I decided to put them in with indvidual names, one other question I do have, is that the email now comes off [email protected]. uk, do you know why and is there anyway I can define whcih server send the mail?


----------



## brendandonhu (Jul 8, 2002)

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 (Dec 17, 2001)

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 (Jul 8, 2002)

What do you mean by the format? It will send whatever is in $message.


----------



## Rutter (Dec 17, 2001)

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 (Jul 8, 2002)

You would have to send it as an HTML message
http://www.zend.com/zend/trick/html-email.php


----------

