Forum Moderators: coopster

Message Too Old, No Replies

php form problem

         

geoffb

7:46 am on Jul 23, 2008 (gmt 0)

10+ Year Member



Hi all,

I have used this similar php form submission code that im having trouble with, except the forms and fields have been only 4/5.

This is a bigger form than I usually use it for and have gone wrong somewhere small I think. It will probably be something obvious.

Whats happening: when I fill in the form online it I just get white blank page www........./appsend.php which is the name of the page containing the php processing.

THE PHP (.../appsend.php)
--------------------------

<?php
if(isset($_POST['Submit'])) {
$title = $_POST['title'];
$surname = $_POST['surname'];
$forename = $_POST['forename'];
$dob = $_POST['dob'];
$status = $_POST['status'];
$dependants = $_POST['dependants'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$employment = $_POST['employment'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$postcode = $_POST['postcode'];
$howquick = $_POST['howquick'];
$whysell = $_POST['whysell'];
$proptype = $_POST['proptype'];
$bedrms = $_POST['bedrms'];
$toilets = $_POST['toilets'];
$garden = $_POST['garden'];
$propcondition = $_POST['propcondition'];
$yeseagent = $_POST['yeseagent'];
$noeagent = $_POST['noeagent'];
$value = $_POST['value'];
$mortgage = $_POST['mortgage'];
$loans = $_POST['loans'];
$whovalued = $_POST['whovalued'];
$yesreposs = $_POST['yesreposs'];
$noreposs = $_POST['noreposs'];
$yesrent = $_POST['yesrent'];
$norent = $_POST['norent'];
if($surname == '' or $forename == '' or $phone == '' or $email == '' or $employment == '' or $postcode == '' or $howquick == '' or $value == '' or $mortgage == '' or $yesreposs == '' or $noreposs == '' or $yesrent == '' or $norent == '')

{
$err = true;
$msg = '*Please complete all marked form fields*';
} else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'title: ' . $title . "\n";
$mailmsg.= 'surname: ' . $surname . "\n";
$mailmsg.= 'forename: ' . $forename . "\n";
$mailmsg.= 'dob: ' . $dob . "\n";
$mailmsg.= 'status: ' . $status . "\n";
$mailmsg.= 'dependants: ' . $dependants . "\n";
$mailmsg.= 'phone: ' . $phone . "\n";
$mailmsg.= 'email: ' . $email . "\n";
$mailmsg.= 'employment: ' . $employment . "\n";
$mailmsg.= 'address1: ' . $address1 . "\n";
$mailmsg.= 'address2: ' . $address2 . "\n";
$mailmsg.= 'postcode: ' . $postcode . "\n";
$mailmsg.= 'howquick: ' . $howquick . "\n";
$mailmsg.= 'whysell: ' . $whysell . "\n";
$mailmsg.= 'proptype: ' . $proptype . "\n";
$mailmsg.= 'bedrms: ' . $bedrms . "\n";
$mailmsg.= 'toilets: ' . $toilets . "\n";
$mailmsg.= 'garden: ' . $garden . "\n";
$mailmsg.= 'propcondition: ' . $propcondition . "\n";
$mailmsg.= 'yeseagent: ' . $yeseagent . "\n";
$mailmsg.= 'noeagent: ' . $noeagent . "\n";
$mailmsg.= 'value: ' . $value . "\n";
$mailmsg.= 'mortgage: ' . $mortgage . "\n";
$mailmsg.= 'loans: ' . $loans . "\n";
$mailmsg.= 'whovalued: ' . $whovalued . "\n";
$mailmsg.= 'yesreposs: ' . $yesreposs . "\n";
$mailmsg.= 'noreposs: ' . $noreposs . "\n";
$mailmsg.= 'yesrent: ' . $yesrent . "\n";
$mailmsg.= 'norent: ' . $norent . "\n";

if (eregi("\r",$email) ¦¦ eregi("\n",$email)){
die ("spam!");

} else {
if(mail('webmaster@example.com, geoffboult@example.com','Web Contact Form', $mailmsg, "From: noreply@example.com","-froot@example.com")) {
header("Location: thanks.html");
}
}
}
}
?>

--------------------------

THE FORM (...apply.php)
--------------------------

<?php
if($err == true) {
echo '<span class="error">'. $msg . '</span>';
}
?>

<form id="form1" method="post" action="appsend.php">
<table width="530" border="0" cellpadding="3" cellspacing="4" class="formstyle">
<tr>
<td align="right" width="250"><strong>Personal Details</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">Title:</td>
<td><select name="title" id="title">
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
</select>
</td>
</tr>
<tr>
<td align="right">Surname:<span class="manditoryindicator">*</span></td>
<td><input name="surname" id="surname" type="text" size="20" maxlength="30" value="<?php echo $surname; ?>" /></td>
</tr>
<tr>
<td align="right">Forename:<span class="manditoryindicator">*</span></td>
<td><input name="forename" id="forename" type="text" size="20" maxlength="30" value="<?php echo $forename; ?>" /></td>
</tr>
<tr>
<td align="right">Date of birth:</td>
<td><input name="dob" id="dob" type="text" size="20" maxlength="20" />
<tr>
<td>&nbsp;</td>
<td><span class="formtxtstyle">Date of birth should be written as: 05/07/2007</span></td>
</tr>
</td>
</tr>
<tr>
<td align="right">Marital Status:</td>
<td><select name="status" id="status">
<option selected="selected">Married</option>
<option>Single</option>
<option>Living with partner</option>
<option>Other</option>
</select>
</td>
</tr>
<tr>
<td align="right">Dependants:</td>
<td><select name="dependants" id="dependants">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>5+</option>
</select>
</td>
</tr>
<tr>
<td align="right">Telephone Number:<span class="manditoryindicator">*</span></td>
<td><input name="phone" id="phone" type="phone" size="20" maxlength="30" value="<?php echo $phone; ?>" /></td>
</tr>
<tr>
<td align="right">Email:<span class="manditoryindicator">*</span></td>
<td><input name="email" type="text" id="email" size="20" maxlength="30" value="<?php echo $email; ?>" /></td>
</tr>
<tr>
<td align="right">Employment Status:<span class="manditoryindicator">*</span></td>
<td><select name="employment" id="employment" value="<?php echo $employment; ?>">
<option>Employed-full time</option>
<option>Employed-part time</option>
<option>Self Employed</option>
<option>Un-employed</option>
</select>
</td>
</tr>
<tr>
<td align="right">Address:</td>
<td><input name="address1" type="text" id="address1" size="30" maxlength="30" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="address2" type="text" id="address2" size="30" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Postcode<span class="manditoryindicator">*</span></td>
<td><input name="postcode" type="text" id="postcode" size="20" maxlength="30" value="<?php echo $postcode; ?>" /></td>
</tr>
<tr>
<td align="right">How Quick Do You Need To Sell:<span class="manditoryindicator">*</span></td>
<td><select class="howquick" id="howquick" value="<?php echo $howquick; ?>">
<option>Within 7 days</option>
<option>Within 1 month</option>
<option>Within 2 months</option>
<option>Within 3 months</option>
</select>
</td>
</tr>
<tr>
<td align="right">Why Are You Selling:</td>
<td><select class="whysell" id="whysell">
<option>Chain broken</option>
<option>Repossession</option>
<option>Relocation</option>
<option>Emigration</option>

<option>Inherited property</option>
<option>Seen another property</option>
<option>Investment property</option>
<option>Struggling to sell</option>
<option>Family reasons</option>
<option selected="selected">Sell and rent back</option>

<option>Sale without hassle</option>
<option>Retirement</option>
<option>Divorce</option>
<option>Bought another property</option>
<option>Other</option>
</select>
</td>
</tr>
</table>

&nbsp;

<table width="530" border="0" cellpadding="3" cellspacing="4" class="formstyle">
<tr>
<td align="right" width="250"><strong>Property Details</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">Type of property:</td>
<td><select name="proptype" id="proptype">
<option>Detached</option>
<option>Semi Detached</option>
<option>Mid Terrace</option>
<option>End Terrace</option>
<option>Detached Bungalow</option>
<option>Semi Detached Bungalow</option>
<option selected="selected">House</option>
<option>Flat</option>
<option>Apartment</option>
<option>Commercial</option>
<option>Land</option>
</select>
</td>
</tr>
<tr>
<td align="right">Bedrooms:</td>
<td><select name="bedrms" id="bedrms">
<option>1</option>
<option>2</option>
<option selected="selected">3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</td>
</tr>
<tr>
<td align="right">Toilets:</td>
<td><select name="toilets" id="toilets">
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<tr>
<td align="right">Garage/Off Rd Parking:</td>
<td><select name="garage" id="garage">
<option>None</option>
<option selected="selected">Single</option>
<option>Double</option>
<option>Driveway</option>
</select>
</td>
</tr>
</td>
</tr>
<tr>
<td align="right">Garden:</td>
<td><select name="garden" id="garden">
<option selected="selected">Front and Back</option>
<option>Back Only</option>
<option>Front Only</option>
<option>Side</option>
<option>None</option>
</select>
</td>
</tr>
<tr>
<td align="right">Property Condition:</td>
<td><select name="propcondition" id="propcondition">
<option>Excellent</option>
<option>Good</option>
<option>Average</option>
<option>Poor</option>
<option>Needs Updating</option>
<option>Needs Refurbishment</option>
</select>
</td>
</tr>
<tr>
<td align="right">Have you appointed an Estate Agent:</td>
<td><input name="yeseagent" type="radio" value="yeseagent" /> Yes <input name="noeagent" type="radio" value="noeagent" /> No</td>
</tr>
</table>

&nbsp;

<table width="530" border="0" cellpadding="3" cellspacing="4" class="formstyle">
<tr>
<td align="right" width="250"><strong>Financial Details</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">Property Value:<span class="manditoryindicator">*</span></td>
<td><input name="value" id="value" type="text" size="20" maxlength="30" value="<?php echo $value; ?>" /></td>
</tr>
<tr>
<td align="right">Outstanding Mortgage:<span class="manditoryindicator">*</span></td>
<td><input name="mortgage" id="mortgage" type="text" size="20" maxlength="30" value="<?php echo $mortgage; ?>" /></td>
</tr>
<tr>
<td align="right">Other Secured Loans:</td>
<td><input name="loans" id="loans" type="text" size="20" maxlength="30" /></td>
</tr>
<tr>
<td align="right">Who Valued Your Property:</td>
<td><select name="whovalued" id="whovalued">
<option>Estate Agent</option>
<option>Surveyor</option>
<option>Self</option>
</select>
</td>
</tr>
<tr>
<td align="right">Are you facing repossession?:<span class="manditoryindicator">*</span></td>
<td><input name="yesreposs" type="radio" value="<?php echo $yesreposs; ?>" /> Yes <input name="noreposs" type="radio" value="<?php echo $noreposs; ?>" /> No
</td>
</tr>
<tr>
<td align="right">Would you like to Rent Back?:<span class="manditoryindicator">*</span></td>
<td><input name="yesrent" id="yesrent" type="radio" value="<?php echo $yesrent; ?>" /> Yes <input name="norent" id="norent" type="radio" value="<?php echo $norent; ?>" /> No
</td>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" id="Submit" type="submit" value="SUBMIT" /> <input name="reset" type="reset" value="RESET" /></td>
</tr>
</tr>
</table>
</form>

Sorry for the long code, its not what I normally do, promise!

geoffb

[edited by: eelixduppy at 1:19 pm (utc) on July 23, 2008]
[edit reason] exemplified [/edit]

MattAU

11:00 am on Jul 23, 2008 (gmt 0)

10+ Year Member



The following code in appsend doesn't display anything, it just sets the variables $err & $msg:

if($surname == '' or $forename == '' or $phone == '' or $email == '' or $employment == '' or $postcode == '' or $howquick == '' or $value == '' or $mortgage == '' or $yesreposs == '' or $noreposs == '' or $yesrent == '' or $norent == '')
{
$err = true;
$msg = '*Please complete all marked form fields*';
}

So if one of those values == '' you get a blank page. I see that you've got the code to display the error message in apply.php, but the error doesn't occur in apply.php, it occurs in appsend.php. You need to display the error message in appsend.php or redirect back to apply.php and display the error there.

geoffb

11:29 am on Jul 23, 2008 (gmt 0)

10+ Year Member



hi matt,

thanks for getting in touch.

not really sure exactly what i need to do.

here is a sample form i have used and is working fine, so why is my other one not?

PHP
--------------------------

<?php
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$foundus = $_POST['foundus'];
$other = $_POST['other'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
if($name == '' or $email == '' or $comments == '') {
$err = true;
$msg = '*Please complete all form fields*';
} else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'Phone: ' . $phone . "\n";
$mailmsg.= 'Email: ' . $email . "\n";
$mailmsg.= 'Foundus; ' . $foundus . "\n";
$mailmsg.= 'Other; ' . $other . "\n";
$mailmsg.= 'Comments: ' . $comments . "\n";

if (eregi("\r",$email) ¦¦ eregi("\n",$email)){
die ("spam!");

} else {
if(mail('webmaster.com, geoff@.com','Web Contact Form', $mailmsg, "From: noreply@.com","-froot@.com")) {
header("Location: thankyou.html");
}
}
}
}
?>

THE FORM
--------------------------------

<?php
if($err == true) {
echo '<span class="error">'. $msg . '</span>';
}
?>
<form id="form1" method="post" action="contactfrm.php">
<table width="525" border="0" cellspacing="6" cellpadding="0" class="formstyle" >
<tr>
<td width="175" align="right">Name:</td>

<td width="350"><input name="name" size="40" type="text" class="text" id="name" value="<?php echo $name; ?>" /></td>
</tr>
<tr align=>
<td align="right">Phone Number:</td>
<td><input name="phone" type="text" size="40" id="phone" /></td>
</tr>
<tr>
<td align="right">Email Address:</td>

<td><input name="email" size="40" type="text" class="text" id="email" value="<?php echo $email; ?>" /></td>
</tr>
<tr>
<td align="right">How You Found Us:</td>
<td><select name="foundus" id="foundus">
<option>Advert</option>
<option>Radio </option>

<option>Recommended</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td align="right">If Other Please State:</td>
<td><input name="other" type="text" size="40" id="other" /></td>

</tr>
<tr>
<td align="right" valign="top">Your Message:</td>
<td><textarea name="comments" cols="35" rows="5" id="comments"><?php echo $comments; ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" value="SUBMIT" /><input name="reset" type="reset" value="RESET" /></td>

</tr>
</table>
</form>

as i say, this form works fine.

geoffb

geoffb

11:30 am on Jul 23, 2008 (gmt 0)

10+ Year Member



hi matt,

thanks for getting in touch.

not really sure exactly what i need to do.

here is a sample form i have used and is working fine, so why is my other one not?

PHP
--------------------------

<?php
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$foundus = $_POST['foundus'];
$other = $_POST['other'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
if($name == '' or $email == '' or $comments == '') {
$err = true;
$msg = '*Please complete all form fields*';
} else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'Phone: ' . $phone . "\n";
$mailmsg.= 'Email: ' . $email . "\n";
$mailmsg.= 'Foundus; ' . $foundus . "\n";
$mailmsg.= 'Other; ' . $other . "\n";
$mailmsg.= 'Comments: ' . $comments . "\n";

if (eregi("\r",$email) ¦¦ eregi("\n",$email)){
die ("spam!");

} else {
if(mail('webmaster.com, geoff@.com','Web Contact Form', $mailmsg, "From: noreply@.com","-froot@.com")) {
header("Location: thankyou.html");
}
}
}
}
?>

THE FORM
--------------------------------

<?php
if($err == true) {
echo '<span class="error">'. $msg . '</span>';
}
?>
<form id="form1" method="post" action="contactfrm.php">
<table width="525" border="0" cellspacing="6" cellpadding="0" class="formstyle" >
<tr>
<td width="175" align="right">Name:</td>

<td width="350"><input name="name" size="40" type="text" class="text" id="name" value="<?php echo $name; ?>" /></td>
</tr>
<tr align=>
<td align="right">Phone Number:</td>
<td><input name="phone" type="text" size="40" id="phone" /></td>
</tr>
<tr>
<td align="right">Email Address:</td>

<td><input name="email" size="40" type="text" class="text" id="email" value="<?php echo $email; ?>" /></td>
</tr>
<tr>
<td align="right">How You Found Us:</td>
<td><select name="foundus" id="foundus">
<option>Advert</option>
<option>Radio </option>

<option>Recommended</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td align="right">If Other Please State:</td>
<td><input name="other" type="text" size="40" id="other" /></td>

</tr>
<tr>
<td align="right" valign="top">Your Message:</td>
<td><textarea name="comments" cols="35" rows="5" id="comments"><?php echo $comments; ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" value="SUBMIT" /><input name="reset" type="reset" value="RESET" /></td>

</tr>
</table>
</form>

as i say, this form works fine.

geoffb

MattAU

12:05 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



Are the PHP & FORM parts both in the same file in that smaller example? That would be the difference.

geoffb

8:35 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



hi MattAU,

Originally I had the form and the php processing code within the same file which was: enquiries.php, but I seperated them a couple of days ago and now the form is on:enquiries.php and the form is pointed to:contactfrm.php which contains the processing code I have given you.

This form works great.

That is why Im a bit stumped.
geoffb

MattAU

10:09 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



There's no way that the given code would work as expected when it's in two different files...

The following is in file A:

if($name == '' or $email == '' or $comments == '') {
$err = true;
$msg = '*Please complete all form fields*';
} else {

But the place to output these variables is in file B:

<?php
if($err == true) {
echo '<span class="error">'. $msg . '</span>';
}
?>

While the form will process correctly if there are no errors, when there are errors you'll get a blank page. You should probably go back and have a check to see whether the one you split up is really working or if you just haven't tested it with empty fields. Variables can't magically 'jump' from one page to another...

Anyway, there are a couple of options to fix it. You can:
- join them up into one page again
- Change the message to say 'Please go back and complete all fields' so the user needs to press the back button

These are probably the best two options. There are other ways but they'll just complicated things more.

geoffb

11:22 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



Hi MattAU

Your right, with un-filled fields just returns blank page.

The problem is that the page the large form is on, I also have to have the other small one, like a quick enquiry type thing, so I wanted to have two separate form processing pages, 1 for each form.

I suppose my first task is to put the error message within the php processing page is it.

Where would be best or does it not matter?

geoffb

MattAU

1:08 am on Jul 24, 2008 (gmt 0)

10+ Year Member



I think that'd be ok for now. Give an error message and tell the user to press the back button to fix the problem.

There's no reason why you can't process two (or 50) forms within one page, but it seems you're fairly new to PHP / scripting so it'll be a bit less confusing having different pages.

geoffb

6:54 am on Jul 24, 2008 (gmt 0)

10+ Year Member



Hi MattAU,

I thank you for your time, you guys (and gals) are an inspiration to many of us new comers, and especially the way you spend ages writing and continuing helping us, even though im sure sometimes you get frustrated with our lack of simple ability sometimes.

I think I shall keep the php processing separate for each form on this occasion, but I am interested to know how you do have the processing of multiple forms within one page, as my limited knowledge of this so far tells me that when the processing of the php form is on the same page, you call the action the same as the file page instead of pointing it to another.

So if you had say 3 forms within and the processing, how can 1 of the forms be sent to the right bit of processing code?

geoffb

MattAU

8:52 am on Jul 24, 2008 (gmt 0)

10+ Year Member



No worries... Everyone's got to start somewhere... I asked a heap of questions when I started a few years ago... :)

Having multiple pages within a single PHP page is easy once you know how. It's not necessarily the best way to do it, but it's an option.

Here's a very basic example with 3 forms:

<?php
if(isset($_POST['form_name']))
{
if($_POST['form_name'] == 'form1')
{
// process form 1
}
elseif($_POST['form_name'] == 'form2')
{
// process form 2
}
else // Process the default form, in this case form 3
{
// process form 3
}
}
?>

<form name="first">
inputs...
<input type="hidden" name="form_name" value="form1">
<input type="submit" value="submit">
</form>

<form name="second">
inputs...
<input type="hidden" name="form_name" value="form2">
<input type="submit" value="submit">
</form>

<form name="third">
inputs...
<input type="hidden" name="form_name" value="form3">
<input type="submit" value="submit">
</form>

etc.

See how each form has the same hidden variable 'form_name'. This makes it easy because you know you'll always have a form_name variable in PHP, you just need to check which form is being processed this time.

geoffb

10:01 am on Jul 24, 2008 (gmt 0)

10+ Year Member



Thanks, I will try and work on this soon and get used to it as another way.

Could you just check out this lastly for me before I bug you too much, I have tried to put the error syntax in with the php processing page, but as im unsure where to put it.

It has just returned a blank page:

<?php
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$foundus = $_POST['foundus'];
$other = $_POST['other'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
if($name == '' or $email == '' or $comments == '') {
$err = true;
$msg = '*Please complete all form fields*';
} else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'Phone: ' . $phone . "\n";
$mailmsg.= 'Email: ' . $email . "\n";
$mailmsg.= 'Foundus; ' . $foundus . "\n";
$mailmsg.= 'Other; ' . $other . "\n";
$mailmsg.= 'Comments: ' . $comments . "\n";

if (eregi("\r",$email) ¦¦ eregi("\n",$email)){
die ("spam!");

if($err == true) {
echo '<span class="error">'. $msg . '</span>';

} else {
if(mail('webmaster@example.com, example@example.com','Web Contact Form', $mailmsg, "From: noreply@example.com","-froot@example.com")) {
header("Location: thankyou.html");
}
}
}
}
}
?>

thanks once again.
geoffb

MattAU

10:18 pm on Jul 24, 2008 (gmt 0)

10+ Year Member



This should work.

<?php
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$foundus = $_POST['foundus'];
$other = $_POST['other'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
if($name == '' or $email == '' or $comments == '') {
$err = true;
$msg = '*Please complete all form fields*';
} else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'Phone: ' . $phone . "\n";
$mailmsg.= 'Email: ' . $email . "\n";
$mailmsg.= 'Foundus; ' . $foundus . "\n";
$mailmsg.= 'Other; ' . $other . "\n";
$mailmsg.= 'Comments: ' . $comments . "\n";

if (eregi("\r",$email) ¦¦ eregi("\n",$email)){
die ("spam!");

} else {
if(mail('webmaster@example.com, example@example.com','Web Contact Form', $mailmsg, "From: noreply@example.com","-froot@example.com")) {
header("Location: thankyou.html");
}
}
}
if($err == true){
echo '<span class="error">'. $msg . '</span>';
}
}
?>