Jump to content

How do you style a php mail form?


munchkinz

Recommended Posts

Hi, I have a (rather long) form on my site that when submitted send the information to me in an email.

Ideally I would like to have the form only send me the information that has been filled out at current it sends everything.

but for now I just need to know how I can style the email so its not one long list. also the form only comes through if an email adress is filled in it says it sends but I never recieve it.

 

heres an example of the code for sending the email

$Date = Trim(stripslashes($_POST['Date'])); 
$Packing = Trim(stripslashes($_POST['Packing'])); 
$Dismantle = Trim(stripslashes($_POST['Dismantle'])); 
$DismantleYes = Trim(stripslashes($_POST['DismantleYes'])); 
$Plumbing = Trim(stripslashes($_POST['Plumbing'])); 
$PlumbingYes = Trim(stripslashes($_POST['PlumbingYes'])); 
$LRSofa = Trim(stripslashes($_POST['LRSofa'])); 
$LRArmChair = Trim(stripslashes($_POST['LRArmChair'])); 
$LROtherChair = Trim(stripslashes($_POST['LROtherChair'])); 
$LRSCabinet = Trim(stripslashes($_POST['LRSCabinet'])); 
$LRLCabinet = Trim(stripslashes($_POST['LRLCabinet'])); 
$LRBookcase = Trim(stripslashes($_POST['LRBookcase'])); 
$LROTable = Trim(stripslashes($_POST['LROTable'])); 
$LRCTable = Trim(stripslashes($_POST['LRCTable'])); 
$LRTVStand = Trim(stripslashes($_POST['LRTVStand'])); 

$Body .= "Date of move: ";
$Body .= $Date;
$Body .= "\n";
$Body .= "Packing: ";
$Body .= $Packing;
$Body .= "\n";
$Body .= "Dismantle: ";
$Body .= $Dismantle;
$Body .= "\n";
$Body .= $DismantleYes;
$Body .= "\n";
$Body .= "Plumbing: ";
$Body .= $Plumbing;
$Body .= "\n";
$Body .= $PlumbingYes;
$Body .= "\n";
$Body .= "\n";
$Body .= "Living Room: ";
$Body .= "\n";
$Body .= "Sofas: ";
$Body .= $LRSofa;
$Body .= "\n";
$Body .= "Arm Chairs: ";
$Body .= $LRArmChair;
$Body .= "\n";
$Body .= "Other Chairs: ";
$Body .= $LROtherChair;
$Body .= "\n";
$Body .= "Small Cabinets: ";
$Body .= $LRSCabinet;
$Body .= "\n";
$Body .= "Large Cabinets: ";
$Body .= $LRLCabinet;
$Body .= "\n";
$Body .= "Bookcases: ";
$Body .= $LRBookcase;
$Body .= "\n";
$Body .= "Occassional Tables: ";
$Body .= $LROTable;
$Body .= "\n";
$Body .= "Coffee Tables: ";
$Body .= $LRCTable;
$Body .= "\n";
$Body .= "TV Stand: ";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: ". $FName ." ". $LName ." <". $Email.">");

// redirect to success page 
if ($success){
header ('Location: thankyou.php');
}
else{
header ('Location: error.php');
}

Link to comment
https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/
Share on other sites

You could test to see if the field is blank before adding it to the e-mail. For example:

 

<?php
...
if($Packing != '') { $Body .= "\nPacking: $Packing"; }
...
?>

thank you for your reply.

Would I need change that for each line of $body? or add it elsewhere?

also would that work for

<?php
...
if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; }
...
?>

Where the input is a dropdown list of numbers 0-4?

Would I need change that for each line of $body? or add it elsewhere?

 

Unfortunately yes, you would need to add a test for each part. Of course, you can group things like:

 

<?php
if($Plumbing != '') {
    $Body .= "\n";
    $Body .= "Plumbing: ";
    $Body .= $Plumbing;
}
?>

 

 

also would that work for

<?php
...
if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; }
...
?>

Where the input is a dropdown list of numbers 0-4?

 

Yep, you can test for whatever value.

Thank you very much for your help, I have done as you suggested, but I am now receiving the following error:

Parse error: syntax error, unexpected '}' in /home/content/59/7338359/html/quoteform.php on line 380

I have checked and cannot see any problem, would it be possible for somebody to take a look and see if they can spot the issue, this website is live and I don't want to lose customers by having a broken website.

 

File attached

 

[attachment deleted by admin]

Would I need change that for each line of $body? or add it elsewhere?

 

Unfortunately yes, you would need to add a test for each part. Of course, you can group things like:

 

<?php
if($Plumbing != '') {
    $Body .= "\n";
    $Body .= "Plumbing: ";
    $Body .= $Plumbing;
}
?>

 

 

also would that work for

<?php
...
if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; }
...
?>

Where the input is a dropdown list of numbers 0-4?

 

Yep, you can test for whatever value.

 

The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value??

The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value??

 

Make sure you surround the output with double quotes:

 

<?php
...
$Body .= "\nFlat Screen TV: $LRFSTV";
...
?>

 

If you look at the output that doesn't show the value, you're probably using single quotes.

The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value??

 

You'll also need to make sure you didn't accidentally remove any dollar signs:

 

<?php
...
$Body .= "\nFlat Screen TV: LRFSTV";
...
?>

Note that there should be a $ before LRFSTV. I tend to make that mistake when cleaning up code in a hurry.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.