• Resolved Psylicium

    (@psylicium)


    I have encountered a problem with my site recently. When I made my current theme back in 2023, I hadn’t implemented comments in it (yet I still got LOTS of pending spam comments in my dashboard), but last week I decided to integrate them again, and at the same time enable Akismet. I made the relevant changes in my theme files, and everything is working frontend-wise.

    However … I never receive any email notifications, when someone comments a post. I have checked “Email me whenever anyone posts a comment/a comment is held for moderation”, but nothing ever shows up – not in my inbox, not in my spam folder. Nothing.

    I know my PHP sendmail is working, because if I logout of the admin panel, and click “Lost password”, I receive an email from “wordpress [at] psylicium.dk” instantly in my inbox. I have also tried running a testmail script manually (outside of my WP installation), and that works flawlessly as well. I have also tried to make a new “mailer [at] psylicium.dk” address with my host and use that instead of “wordpress [at] psylicium.dk”, thinking it was some blacklisting issue or something.

    I also suspected there maybe was an error in my template or some plugin broke the functionality, so I also tried to disable them all and switch to the Twenty Twenty-Four theme. Still no emails.

    I tried reinstalling WP, thinking some core files were corrupt or something. Same issue 🙁

    As a last resort, I tried some plugins, WP Mail SMTP Pro and Post SMTP, using my host’s SMTP server and the “mailer [at] psylicum.dk” address. I could send test emails with no problems from the plugins, but if I tried to comment, I got errors in the log: “Mails of this type are blocked to external recipients. Please send within your own domain (d42a6a9d-28d2-11f0-92cf-b9c09f58dc4b) WPC”. But I would rather not use plugins, as the PHP mailer has worked previously, and apparently still does – just not for the darn comments.

    I have struggled with this the entire weekend, and can’t for the life of me figure out what’s wrong. Has anyone experienced a similar issue, and can point me in the right direction?

    I’m running WP 6.8.1 and PHP 8.2.

    Thanks,
    Henrik

    • This topic was modified 1 year, 1 month ago by Psylicium.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    AFAICT, the “me” in “Email me whenever anyone posts a comment” pertains to the post’s author, not the site admin. When that box is checked, the site admin doesn’t get notified, but the post author does, whether the commenter is pre-approved or not.

    I would agree it’s not the behavior implied by the setting’s wording, but I believe the behavior is intentional none the less.

    If you as site admin wish to be notified as well, you could use the ‘notify_moderator’ filter to always return true. Some custom coding is required to utilize filters, unless you can find a plugin that does this for you.

    Thread Starter Psylicium

    (@psylicium)

    I don’t think the notification mails are only meant for authors, because on this page, it states that the “me” refers to either an author or administrator. So you are partly right – the “Anyone posts a comment” option only notifies the author of replies, whereas the “comment held for moderation” are meant for the administrator email listed in Settings > General. But since I am both the author and the administrator using a single account, I should receive a notification in either case.

    I troubleshooted some more today, thinking something in my database was awry, so I deleted everything and did a clean install of WordPress – same issue 🙁 The last thing I can come up with, is that my hosting provider perhaps blacklisted something due to all the spam comments I received before starting to use Akismet. I am waiting for their reply now, but if they didn’t block something, and everything looks good on my domain, I am out out of ideas…

    BTW: The ‘notify_administrator’ hook did work – I got a mail. I used some simple demo script I found, that just said “You have a new reply”, and if it turns there’s no issues with my host, I may use this as a last resort. I just have to figure out how to customize it to also include the post title and an excerpt of the comment. There’s probably some variables or functions for that 🙂

    Moderator bcworkz

    (@bcworkz)

    I just have to figure out how to customize it to also include the post title and an excerpt of the comment.

    The standard message when “notify_moderator” hook returns true should already include that information. In any case, the ‘comment_moderation_text’ filter hook can be used to modify the message any way you desire. The default message and comment ID are passed to the added callback.

    It sounds like you’re using the “notify_moderator” hook as an action event to send a separate message. What is your callback returning? It ought to return true to get the normal moderation message, even if the comment got automatically approved. If you get the WP_Comment object from the passed ID, its comment_approved property will indicate whether the comment was approved or not, or was spammed. You may then adjust the message accordingly.

    Thread Starter Psylicium

    (@psylicium)

    So … I got a reply from my host, and if I have to be honest, they are far from helpful 🙁 “Make sure your SMTP is setup correctly”, link to a WP SMTP Mail plugin (which I’ve already tried with no success) and a guide. Followed it, and like before, I can send test mails, but whenever I comment, I still get the same error as in my first post. And “besides that, we can’t give further support on WordPress regarding email systems”. Well, thanks for nothing!

    I replied them with the complete error log, and insisted that something is wrong on THEIR side, as you know – it works perfectly sitewise, EXCEPT for the comments. I then tried a few mail logging plugins, and as I suspected: no errors when I request a new password or send test emails, but of course the usual when commenting. I couldn’t get detailed logs, as all I got was “could not instantiate mail function”. So far, so good. Something specifically in the comment routine, or what you call it, is triggering the error, as far as I can tell. Well, obviously I was aware of that all along, but somehow (and I can’t remember how), I got a backtrace log of what actually happens when a comment is posted:

    [0] wp_mail called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/pluggable.php:2069]
    [1] wp_notify_moderator called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/comment.php:2406]
    [2] wp_new_comment_notify_moderator called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/class-wp-hook.php:326]
    [3] WP_Hook->apply_filters called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/class-wp-hook.php:348]
    [4] WP_Hook->do_action called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/plugin.php:517]
    [5] do_action called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/comment.php:2380]
    [6] wp_new_comment called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-includes/comment.php:3743]
    [7] wp_handle_comment_submission called at [/customers/0/c/d/psylicium.dk/httpd.www/wp-comments-post.php:25]

    I know I shouldn’t edit those files, but I’ll go through them tomorrow to see if I can make some changes to get it functional. Stay tuned.

    Moderator bcworkz

    (@bcworkz)

    I’m inclined to agree with your host that the issue lies within WP and their server’s email functionality is working as expected.

    It’s your site, you may edit core files 😉 Just be aware that any changes will likely be reverted during the next update. Correcting undesired behavior is best accomplished by using available filter and action hooks, via callbacks added from a custom plugin. Then any alterations will remain in place during updates.

    OTOH, if you wish to propose a change to core code via the Trac system, it’s very helpful when you can point to exactly where the problem lies in the code and how it needs to change in order to improve functionality.

    Thread Starter Psylicium

    (@psylicium)

    God, I’m so stupid, and my host’s info isn’t exactly clear regarding mail configuration.

    Turns out that I can ONLY send mail from my own domain, psylicium.dk, and I missed ONE thing over and over again… Like I wrote in my initial post, I created several new mail addresses for my domain, and this time I also changed the WP admin email to those, but the problem persisted, and in the logs, there still was a gmail address that broke things – but I was sure I had changed everything to my psylicium.dk mail address.

    And THEN it dawned on me … my user profile still had a gmail address! I haven’t at any point thought that the admin and user profile was two different things. I just assumed, that since I’m the only user, the admin email was reflected in the user profile, if I changed it 😑

    I changed the user email address to my psylicium.dk one, and set the admin one back to my original gmail one. And that did the trick! No errors in the mail log, and the comment approval email arrived immediately.

    So, to sum up, if anyone else has a problem with WordPress on a one.com host:

    You can’t use an external email like gmail in the user profile – only a valid email address that belongs to your domain, like me[at]mydomain.com

    I was sure it worked sometime in the past, but now I think about it, it might have been with my previous host. I switched some years ago, and just imported the database from the old host to one.com – gmail and all. And since I haven’t been using comments for years, I just noticed the problem now.

    Everything seems to be in working order now, so I’m marking it as resolved – and thanks for your feedback 🙂

    • This reply was modified 1 year, 1 month ago by Psylicium.
    Moderator bcworkz

    (@bcworkz)

    I’m glad you’ve resolved the issue! As you have implied, not all hosts allow their servers to send email from a non-domain address. There are some that do allow it, but it’s still advisable to not do so because non-domain email is much more likely to get marked as spam and discarded along the way. This is largely because non-domain email will not have appropriate anti-spam header information (SPF, DKIM, etc.).

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Not receiving emails when someone comments’ is closed to new replies.