By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,021 Members | 952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,021 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sigmund wrote:
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.


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.
Jul 17 '05 #2

P: n/a
On Tue, 07 Dec 2004 21:22:39 -0800, Mark <mw@ANGRYLanfear.com> wrote:
Sigmund wrote:
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 :
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:


Thanks - I'm going to work on this.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.