RE: [PHP] PHP logic - Whats going on here?
| From: | Jay Blanchard | Date: | Wed, 11 Aug 2004 13:13:34 +0000 |
| Subject: | RE: [PHP] PHP logic - Whats going on here? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-193447@lists.php.net to get a copy of this message | ||
[snip]
Then to send the mail we use this :
if(!$mail->Send()) {
echo $lang_error['mailer_error'] . "<br>\n";
}
As you see above, Ive dropped the "what if all goes well" loop, since I
believe that the $mail->Send() is initiaded in the first statement....
For some reason the above results in a blank mail, no $body at all,
rest is fine. However, if I include a dummy for if all goes well :
if(!$mail->Send()) {
echo $lang_error['mailer_error'] . "<br>\n";
} else {
// Why do I need this one???
}
What I dont understand is why do I need the last else statement? Isnt
the
result of $mail->Send() completed if I only check for !$mail->Send()?
[/snip]
This is fairly standard in programming languages all the way around. The
'else', even if a dummy, is the antithesis of the NOT statement. Think
of it this way ...
----my code----
if($mail->Send()){
// sends mail because $mail->Send evaluates to TRUE
} else {
// evaluates to FALSE
echo $lang_error['mailer_error'] . "<br>\n";
}
----my code----
----your code----
----my comments----
if(!$mail->Send()) {
// if $mail->Send is FALSE 'if' evaluates TRUE
echo $lang_error['mailer_error'] . "<br>\n";
} else {
// $mail->Send evaluated to TRUE, without 'else' it is has no
place to 'act'
// Why do I need this one???
}
----your code----
I hope that helps, may not be crystal clear.