tags:

views:

37

answers:

2

Hello

I have this function:

function sendEmail ($to, $id, $from='n', $link='n') {

    //retrieve message from system
    $where = "id = '".$id."'";
    $resource = dbSelect (TMAIL, $where);

    if ($resource[0] !== 1) {
        return "Error sending email";
    }

    $subject = $resource[1]['subject'];
    $body = $resource[1]['body'];

    //create and send email
    if ($link !== "n") {
        $body = $body.' <a href="'.$link.'">'.$link.'</a>';
    }
    if ($from == 'n') {
        $from = ADMIN;
    }

    mail ($to, $subject, $body, $from);

    //deubug
//print_r($resource);
    //echo $from;
    //echo $to;
    //echo $subject;
    //echo $body;
    //echo $link;
}

Being called like this:

//send instructions
        $f_error['failure'] = sendEmail ($email, "1", ADMIN, $link);
        $f_error['failure'] = sendEmail (ADMIN, "2");

In the above case the first call to sendEmail doesn't appear to do anything and the second being sent twice. I've checked the variables/constants being sent to the function and the code itself and can find nothing to explain this behavior.

Can anyone suggest what could be preventing this from working?

A: 

Couple of things:

  • If the ID is a number, don't put it in quote marks

  • "ADMIN" is not a valid email address (unless you are delivering locally)

  • Have a look at http://uk3.php.net/manual/en/function.mail.php - the way you are setting your 'from' headers doesn't look correct.

palmaceous
The quotes don't matter. Every DB i can think of allows numbers to be quoted, and a couple of weird ones may even *require* it.
cHao
ADMIN is a constant. It could very well be a valid email address, if that's what it's set to.
cHao
A: 

Found the problem - the first message was going into my junk mail and the second wasn't. I assumed both would end up in the same folder.

YsoL8