Returns Bool??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anomaly
Forum Newbie
Posts: 15
Joined: Mon Oct 21, 2002 9:45 pm

Returns Bool??

Post 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
}
Last edited by anomaly on Sun Oct 27, 2002 12:08 pm, edited 2 times in total.
anomaly
Forum Newbie
Posts: 15
Joined: Mon Oct 21, 2002 9:45 pm

Post 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);
}
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
anomaly
Forum Newbie
Posts: 15
Joined: Mon Oct 21, 2002 9:45 pm

Post by anomaly »

so if I edited that function and said

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

Would I be able to test it?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

yep

Post by AVATAr »

yep :wink:
Post Reply