follows either of the above methods of redirection, the file does not work properly. Only the error.htm file is invoked but never the ok.htm file. Does anybody know why? Why does the order of commands matter in this case?
does two things: It gives a value to $success, and it sends an email message.
I was focused on the sending of the email message. It seemed that something must have been set to allow that message to be sent. It seemed that whatever permits the message to be sent could permit it to be sent at any time. I missed the fact that the redirection section does it job on the basis of the value in $success. Please correct me if I’m wrong, but apparently, some mechanism sends the message independent of setting the value of $success.
Do not mistake this for “it returns a boolean value which indicates whether the email was correctly received by the recepient.”.
PHP only returns whether it was able to send the e-mail, it’s clueless as to whether the e-mail was actually delivered.
if goods paid for
then take goods home
else leave without goods
search store for goods to purchase and if something suitable found then pay for it
If you follow that order of doing your shopping then you will always take the leave without goods for because you haven’t yet paid for the goods that you haven’t yet found.
You must perform step 2 before step 1 in order for step one to ever take the take goods home path and the same applies in programming code.
With your statements reversed your code effectively says
if the email sent properly
then go here
else go there
try to send the email and record whether it sent properly or not
Exactly. The real “work” of the statement is sending the email which is performed by the mail() function. If that was it, this would technically be a routine with “void” output. However, mail() does return a value, so it’s techinically a function; it returns a boolean value which indicates whether the email was correctly sent. That’s why you can then use $success (but only after you’ve tried to send the email, because otherwise the mail() function hasn’t returned a value for it yet) in an if statement.