Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
December 8, 2004, 9:09 am
rate this thread
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
Re: Can a control statement go within a mail() function?
NO control structures in expressions. They're not the same things.
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.
$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.