Can a control statement go within a mail() function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sigmund

    Can a control statement go within a mail() function?

    Hi,

    I would like to put an IF statement within the mail() function. I've
    tried this and searched around but haven't found anything written
    about this. Is it possible? I've been doing somethings like :

    mail ("Email", "Subject", "Body".if() {...}."", "From");

    Sorry if this is a dumb question. BUT, if it works I will try similar
    things in SELECT statements.

    Thanks in advance
  • Mark

    #2
    Re: Can a control statement go within a mail() function?

    Sigmund wrote:
    [color=blue]
    > Hi,
    >
    > I would like to put an IF statement within the mail() function. I've
    > tried this and searched around but haven't found anything written
    > about this. Is it possible? I've been doing somethings like :
    >
    > mail ("Email", "Subject", "Body".if() {...}."", "From");
    >
    > Sorry if this is a dumb question. BUT, if it works I will try similar
    > things in SELECT statements.[/color]

    Short Answer:

    NO control structures in expressions. They're not the same things.

    Better Answer:

    This is a very common request, so PHP, among a few other languages, has
    something called the ternary operator, which acts as an expression:

    (expr1) ? (expr2) : (expr3)

    expr1 is evaluated. If TRUE, expr2 is evaluated and is the result of the
    ternary operator. Otherwise, expr3 is evaluated and becomes the value of
    the ternary operator.

    For example:

    $is_it_a_dog = FALSE;

    //
    // animal has "cat" after this.
    //
    $animal = $is_it_a_dog ? "dog" : "cat";

    $some_number = (time() % 2) == 0 ? pi() : 2.71828;

    play around with it. it's likely what you want.


    --
    I am not an ANGRY man. Remove the rage from my email to reply.

    Comment

    • Sigmund

      #3
      Re: Can a control statement go within a mail() function?

      On Tue, 07 Dec 2004 21:22:39 -0800, Mark <mw@ANGRYLanfea r.com> wrote:
      [color=blue]
      >Sigmund wrote:
      >[color=green]
      >> Hi,
      >>
      >> I would like to put an IF statement within the mail() function. I've
      >> tried this and searched around but haven't found anything written
      >> about this. Is it possible? I've been doing somethings like :[/color][/color]
      [color=blue]
      > Short Answer:
      >
      > NO control structures in expressions. They're not the same things.
      >
      > Better Answer:
      >
      > This is a very common request, so PHP, among a few other languages, has
      >something called the ternary operator, which acts as an expression:[/color]

      Thanks - I'm going to work on this.

      Comment

      Working...