I have my sendmail.php working properly, I am wanting to know if there is a way to set conditions. Example: In my form I have a line called, 'color'. So in sendmail $color is used to grab the 'color' field in the form. To help distinguish what data is shown in the email I have added lables to them. Name = $name Color = $color Type = $type etc.. Well If someone does not fill out the 'color' field in the form is there a way to comment out the line completely so that way I am not left with just a blank line Color = (nothing) I would rather see Name = $name Type = $type etc...
You can test the variables first if they are empty. Example: $msg = ''; if($name) $msg .= 'Name : ' . $name; if($color) $msg .= 'Color : ' . $color; ... ... and so on.
fairuz.ismail is right but it's better to use isset function rather than test the variable in the if statement.. $msg = ''; if(isset($_REQUEST['name'])) $msg .= 'Name : ' . $_REQUEST['name']; if(isset($_REQUEST['color'])) $msg .= 'Color : ' . $_REQUEST['color']; if(isset($_REQUEST['type'])) $msg .= 'Type: ' . $_REQUEST['type']; PHP:
When I use isset i get this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /website/form/sendmail.php on line 25: line 25:
When I use: I get; The First line shows the information used in the form. The Second line shows it empty because nothing was in the form.