开发者

PHP function sends some mail, not others

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(开发者_Python百科$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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜