#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    59
    Rep Power
    1

    Help with a part of code


    PHP Code:
    $receiver = isset($_POST["receiver"]) ? $_POST["receiver"] : false;
    $res mysqli_query($GLOBALS["___mysqli_ston"], "SELECT acceptpms, email, notifs, last_access as la FROM users WHERE id=$receiver") or sqlerr(__FILE____LINE__);
    $user mysqli_fetch_assoc($res);

    if (
    strpos($user['notifs'], '[pm]') !== false){
    $username $CURUSER["username"];
    $body = <<<EOD
    You have received a PM from $username!
    You can use the URL below to view the message (you may have to login).
    {$url/messages.php
    --
    {[
    'site_name']}
    EOD;
    @
    mail($user["email"], "{$lang['message_received']} " $username "!",
    $body"{$lang['message_from']} {['site_email']}");
    }
     
    so I have the code above that will allow members that have in their profile set the option to receive an e-mail each time they receive a PM on the site... and it works.
    which doesn't work is when they receive notifications from the site. they receive the PM normally but they don't receive the e-mail about it.
    The sender of notifications is not really an account, it has id=0 and username 'System'.
    How would this need to be modified so that members will also receive e-mail when they get PM from that "non-account/System" ?
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    PHP Code:
    "{$lang['message_from']} {['site_email']}" 
    That is wrong (for two reasons) but if it works for PMs then it should work for site notifications too.

    Besides the most noticeable problem, that parameter is not a proper mail header: (a) it must not be localized and (b) it has the wrong syntax anyways.
    PHP Code:
    "From: {$???['site_email']}
    1. Don't @ suppress the error. Let it happen. Because obviously there's some sort of problem.
    2. Take an action if the mail sends or errors - log it, display a message, whatever.
    3. If you still have problems then dump/log the $user, $lang, $username, $body, and $??? variables, then check if they have the values you think they have.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    59
    Rep Power
    1
    There is no error. Like i said, it works for normal users sending messages too each other.
    user 1 sends message to user 2. User 2 if he has the option enable in his profile will receive e-mail notification about PM on site
    user 2 receives notifications from the site a.k.a from 'System', massPM, class upgrade and so on.. but he didnt receives e-mail to notify him of that
    The initial code is good, just needs to be modified. The variables for this example were just edited/obscured.
    Thats why i made this post to receive info on how it should be modified further so that members will also receive e-mail notification when they receive PM on site from the System also.
    Last edited by pwpx2; October 4th, 2017 at 02:51 AM.
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    Originally Posted by pwpx2
    There is no error.
    Oh, so the email system is now working? Or are you going to tell me that the email not working is, in fact, not an error?

    Fix the From header, remove the @, and act on the return value.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    59
    Rep Power
    1
    The e-mail system is working. I already told you what is not working. When a member from the site receives a PM on the site he should receive an e-mail to notify him.(maybe he is not on the site or away)
    This works only when another user is sending the PM and not the automatically System. Maybe someone sent a massPM or he get promoted to another class. He receives the PM from the auto-system but never receives the e-mail about this.
    This is what i am trying to say.
    I removed the @. The error logs/mail logs are not displaying anything wrong.
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    Originally Posted by pwpx2
    The e-mail system is working.
    Except when it doesn't.

    Originally Posted by pwpx2
    I removed the @. The error logs/mail logs are not displaying anything wrong.
    Did you do the other things I said?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    59
    Rep Power
    1
    Yes i did.
    Maybe i need to add other things to the code? Since it works when members receive PM from other members but not from System ?
  14. #8
  15. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    What was the return value from mail()? What did your logging of the assorted variables involved show?

IMN logo majestic logo threadwatch logo seochat tools logo