Kim Steinhaug wrote:
[snip]
> 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?

You shouldn't.

> Isnt
> the result of $mail->Send() completed if I only check for
> !$mail->Send()?

Yes.

> Maby it would be better to write like this :
>    if(!$mail->Send()) {
>       echo $lang_error['mailer_error'] . "<br>\n";
>    } else if ($mail->Send()){
>       // Why do I need this one???
>    }
>
> The above would in my belief send two mails, atleast my logic tells
> me that.

I'm not familiary with phpMailer, or exactly how the Send method words, but the code
above would end up calling the Send method twice.  If the Send method does in fact
send (as its name suggests) then you probably don't want to call it twice when you
intend to send the message only once. :)

[snip]
> Hope someone understand what Im wondering about here, hehe.

In PHP (and every language that I've ever used...) an if statement's expression is
evaluated regardless of whether there is an else portion, or an elseif, etc.  For
example, suppose we have a function foo() that is evaluated primarily for its side
effects, but may return either true or false to indicate if the function was
successful.  This:

if (foo()) {
  print "foo() was successful!\n";
}

is functionally equivalent to this:

if (foo()) {
  print "foo() was successful!\n";
} else {

}

The null else clause should have no effect whatsoever on the execution of the
script.  In fact, the following code snippets are all functionally identical:

//Version one
foo();

//Version two
if (foo()) {

}

//Version three
if (!foo()) {

} else {

}

In all three cases foo() is evaluated just once.

Something else you should be aware of:  When the expression in the if statement is a
compound expression (it contains multiple expressions), then the PHP parser uses
"lazy" or "short-circuit" evaluation.  This means that the parser only evaluates the
portions of the expression that are necessary to calculate the result of the entire
expression.  An example:

if (foo() && bar()) {
  //Do stuff
}

In the above example, foo() is evaluated first.  If foo() returns false, bar() is
not evaluated at all.  The reason is that no matter what bar()'s return value is,
the entire expression can only be false.  Since the parser has already determined
the final result, it has no need to evaluate any further terms.  Similarly:

if (foo() || bar()) {
  //Do stuff
}

In this example, bar() will not be evaluated if foo() returns true, but will be if
foo() returns false.  These are obviously simple examples, but basically the parser
only evaluates the terms that are necessary and doesn't go any further.  This can be
used as a type of flow control to have certain functions/methods called only if
another returned true or false.  For example, the following two code snippets are
functionally identical:

//Version one
if (foo()) {
  bar();
}

//Version two
if (foo() && bar()) {

}

As far as your specific problem, I suspect that there are factors at play that you
are not aware of.  Either you have run across a bug in the PHP parser itself
(unlikely), or you are inadvertently making other changes when you add the else
clause.  I would suggest using basic debugging techniques to echo/print the contents
of the body string at various points to see what it contains.  You may need to drill
down into the actual source code for the Send() method to see what it things the
body string is.  If something is happening to this value this approach should reveal
where it's occuring.

HTH...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to