Page 1 of 1

Returns Bool??

Posted: Sun Oct 27, 2002 12:03 pm
by anomaly
I'm working with a function that returns a bool, true if it was successfull and false if not. What kind of if statement would I need to check if this function was succesfull? I tried the two below(just expamples) and they don't seem to be working...

Code: Select all

if(pnMail($param1, $param2, $param3, $param4) == true)
{
commands here
}

if(pnMail($param1, $param2, $param3, $param4) == 1)
{
commands here
}

Posted: Sun Oct 27, 2002 12:07 pm
by anomaly
Here is the function I am using, it is completing succesfully, but I would like to check whether it did or not.

Code: Select all

/**
 * send an email
 * @param to - recipient of the email
 * @param subject - title of the email
 * @param message - body of the email
 * @param headers - extra headers for the email
 * @returns bool
 * @return true if the email was sent, false if not
 */
function pnMail($to, $subject, $message, $headers)
{
    // Language translations
    switch(pnUserGetLang()) {
        case 'rus':
        if (!empty($headers)) $headers .= "\n";
            $headers .= "Content-Type: text/plain; charset=koi8-r";
            $subject = convert_cyr_string($subject,"w","k");
            $message = convert_cyr_string($message,"w","k");
            $headers = convert_cyr_string($headers,"w","k");
            break;
    }

    // Mail message
    mail($to, $subject, $message, $headers);
}

Posted: Sun Oct 27, 2002 2:41 pm
by twigletmac
You're not actually returning anything from that function, the mail function within in it will be returning true or false but that's not the same as the pnMail() function returning true or false.

http://www.php.net/manual/en/functions. ... values.php

Mac

Posted: Sun Oct 27, 2002 8:14 pm
by anomaly
so if I edited that function and said

return mail($to, $subject, $message, $headers);

Would I be able to test it?

yep

Posted: Sun Oct 27, 2002 10:59 pm
by AVATAr
yep :wink: