#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Omaha
    Posts
    5
    Rep Power
    0
    Hello,

    I was wondering if there is any way to nest if statements inside of a mail command so that I can choose what to include in the mail command.

    More specifically, I have a dynamic table and a ton of array files passing from the form passing to the send page. Some of these fields can be left empty. Is there a way to include only those fields that are filled in or do I have to include all the fields?

    Thanks!

    Michael
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    You can dynamically generate the body of the email before sending it. You can basically just add to a vraibale that will hold the body of the message like so:

    if ($name) {
    $body .= "Name= " . $name ."n";
    }
    if ($email) {
    $body .= "Email= " . $email ."n";
    }
    if ($address) {
    $body .= "Address= " . $address ."n";
    }
    mail("to", "subject", $body);
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Omaha
    Posts
    5
    Rep Power
    0
    Just for clarification purposes, the form I'm using uses checkboxes to signify if something is to be used or not since there are tons of sections to this form.

    Basically I could do something like this to set what goes into the mail command:

    for ($x=0; $x<=11; $x++) {
    if ($checkbox[$x] == true) {
    $body = $values[$x];
    }
    }

    then have the mail command be this:

    mail("to", "subject", $body);

    Would that work?

    Michael
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    Yeah just make sure to use the .= in your $body line like:
    $body .= $values[$x];


    for ($x=0; $x<=11; $x++) {
    if ($checkbox[$x] == true) {
    $body = $values[$x];
    }
    }

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. Help with script
    By akastarlight in forum Perl Programming
    Replies: 1
    Last Post: February 6th, 2004, 06:55 AM
  3. mail() function dropping characters
    By Webbywarehouse in forum PHP Development
    Replies: 2
    Last Post: January 28th, 2004, 01:42 PM
  4. mail function smtp problem
    By emzyme in forum PHP Development
    Replies: 3
    Last Post: January 25th, 2004, 06:59 PM
  5. Help with the mail() function
    By n000b in forum PHP Development
    Replies: 2
    Last Post: January 24th, 2004, 08:14 AM

IMN logo majestic logo threadwatch logo seochat tools logo