Help with Sendmail.php

Discussion in 'PHP' started by @Fitz, Sep 28, 2011.

  1. #1
    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...
     
    @Fitz, Sep 28, 2011 IP
  2. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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, Sep 29, 2011 IP
  3. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #3
    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:
     
    JohnnySchultz, Sep 29, 2011 IP
  4. @Fitz

    @Fitz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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:
     
    Last edited: Sep 29, 2011
    @Fitz, Sep 29, 2011 IP
  5. @Fitz

    @Fitz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    @Fitz, Sep 29, 2011 IP