Appointment reminders sent twice

For most of the booked appointments, the reminder e-mail is sent twice to the same recipient (booking customer) at the same time. Reminders should be sent 24 hours before an appointment and in around 60% of cases, two of them go out at once. Around 40% of cases - there's only one reminder. The issue is quite intermittent but A+ log confirms it.

  • Ivan

    Hi David @ BBS !

    Are you sure that reminders were sent twice? I found that the plugin has a check for sending duplicated reminders but yes, it will be logged twice (it will be fixed in the next version of the plugin). It means that you can only see it in the A+ log but it was sent once.
    Also, I see that you selected to send reminders only 24 hours before an appointment. If you also want to send it when appointments starting - you can try to set 24, 0 in the Reminder email Sending Time for the Client (hours) setting (WP Dashboard -> Appointments -> Settings -> General -> Notifications -> Reminder email Sending Time for the Client (hours) )

    Best,
    Ivan.

  • Ivan

    Hi David @ BBS !

    A+ log confirms it.

    I checked the Appointments Log and I see that the last duplicated entries were on March 22, 2017 6:58 pm. (if you will recheck it - make sure that entries have different emails and different ID of appointments )
    Also, I created new customer on your site with ioannup username with my real email. Could you create test appointment for me on your site for checking this issue?

    Best,
    Ivan.

  • David @ BBS

    Hi Ivan! Happy New Year!!! :smiley:

    Thanks for taking a look at this. Just created 3 different appointments for you. Let's see how they behave. Since the Test2 site is a clone of the Test site (which is really used for our internal testing), no real appointments are ever done there. To get a real grasp of the problem, I invite you to check out the Appointments Log on the live site (I re-granted you access):
    https://www.broadwaybabysitters.com
    In just the last two weeks you'll find 6 instances of reminder emails having been sent two times.

    Curious to hear what you find.
    David

  • David @ BBS

    Hi Ivan!

    Thanks for checking in. The appointments did happen and the reminders were sent (since it's a test site, and nobody had logged in for a while, cron didn't run till today when I loaded the site - but once I did all reminder emails got sent out). But since this is a test site I'm running an additional plugin that reroutes all emails to be sent to me (the admin) rather than to original recipients. After all, I don't want clients or our babysitters freaking out about fake appointments. :slight_smile:

    Having said that, here's what's interesting. I had created 3 appointments for you.

    Here are the reminders that I received:

    The first appointment: 2 reminders were sent to you (the client), 2 reminders to the service provider.
    The second appointment: 2 reminders were sent to you (the client), 2 reminders to the service provider.
    The third appointment: NO reminders were sent to you (the client), 2 reminders to the service provider.

    Definitely strange. The logs confirm that. But of course a single instance for each.

    I see that you created an account on our live site. I've created 3 new appointments for you on the live site for Sunday 7th @ 10am, 4pm and 7pm. So hopefully tomorrow (on Saturday) you receive email confirmations of those. I did do a DIFF on the plugin code and see the modification you made. Great catch. From the looks of it, it should fix the issue. I'm curious to hear how it goes. :slight_smile:

    Thanks!
    David

  • Ivan

    Hi David @ BBS !

    It seems grant access to your main site was expired.
    It's better if you provide us more credentials for investigation this issue.

    https://premium.wpmudev.org/contact/#i-have-a-different-question
    Please visit our private Contact page and complete the form with the following information:

    Subject: "Attn: Ivan Svyrskyi"

    In the Message box, please provide the following:

    link back to this thread for reference
    any other relevant urls

    Admin login:
    Admin username
    Admin password
    Login url

    FTP/SFTP credentials
    host
    username
    password
    (and port if required)

    Note: Don't send any credentials via this forum because it's public forum.

    Also, I got two emails for Sunday 7th @ 10am and one email for 4pm and one email for 7pm.
    SO, the last two reminders look fine.
    Regarding the first one - Could you check how many entities does the A+ log have for this reminder? If there is one entity there - it looks like a conflict with another plugin or theme. Could you deactivate all plugins except A+ (including all plugins for SMTP and so on) and switch theme to the 2017 default theme and test it again?

    Best,
    Ivan.

  • David @ BBS

    Hi Ivan!

    Thanks for being willing to keep looking into this!

    Would you be kind enough to grab all the login credentials to the live site from Predrag Dubajic as I'd already submitted it all to him last month when him and I were testing a PHP error thrown by the Membership plugin? Thanks!

    As for the email reminders here's what the logs show: All three of your appointments sent out 1 reminder to you and one reminder email to the service provider. Glad to hear you received all (although the 10am still seemed double?)

    On the other hand, I created 2 test appointments with Barbra for myself (one under my admin account and one under my test customer account). Barbra received all 5 email reminders (3 for yours, 2 for mine). However I didn't receive a single reminder for either of my appointments. And the logs confirm this. :disappointed:

    As for testing any plugin conflicts, I'm unable to do that on the live site as we have too many active customers. However that's why I created the test2 clone site. So you're welcome to do as many tests as you'd like. Change themes, change plugins, etc. Have fun with it! :slight_smile: IMPORTANT NOTE: The only plugin that has to remain active is "WP Reroute Email". After all, I don't want customers to accidentally start receiving emails from the test sites. As a precaution I removed the option for that plugin to be deactivated on the test site. Aside from that, feel free to test everything you need. I'm curious to hear your results! :smiley:

    Thanks!
    David

  • Michael

    Hola - I think I may be able to help here! I did not read through the other responses, so forgive me if I repeat something someone else has said. First question is, are you on a shared hosting plan? If so, who is your host? Do you have an SMTP plugin setup? If so, are you using Google G Suite?

    This is an issue that affects many plugins. If you do not use an SMTP plugin, you are relying on cron jobs that take advantage of the php mailer. If your host server is slow, there is a good chance that the sending function times out, then simply repeats.

    I have gotten around this by using Mailgun, or GMAIL SMTP.

    Hope this helps.

  • David @ BBS

    Hey Michael,

    Thanks for chiming in with some really great notes.

    To answer your questions: yes we're on a shared hosting plan on BlueHost. But we are already using the Easy WP SMTP plugin. And yes, our domain's emails are handled by Google G Suite. (Although the SMTP plugin is still configured to send through a different SMTP server. Which I need to change...).

    Ivan & Michael: Do you recommend the GMAIL SMTP plugin over EASY WP SMTP?

    What's strange is why would this double sending (or now even sometimes non-sending) of emails happens only in the case of the appointments plugin? Especially when our site sends out so many different notifications and the rest of them work fine? Peculiar indeed.

    Curious if

  • Michael

    Darn it, I was hoping that was the winner. I have never used Easy WP. BUT I do have great success in using GMAIL SMTP with my G Suite Oauth.

    The good people at wpbeginner.com have some great tuts on email issues. However those deal with email NOT sending :slight_smile: you send to much.

    The only thing I can think of is some sort of cron issue, but that should be solved with an SMTP plugin.

    Let me email a buddy tomorrow am and get his take. This is right up his ally.

    But the most perplexing thing is just the appointments plugin... um... wait!

    ON YOUR appointment page did you build it or use the template that auto creates in the settings?

    Curious if maybe there is a double setting.

    I am going to keep thinking on this one.

  • Ivan

    Hi David @ BBS !

    I got email and it was once. So, it means that it's not an issue of the A+ plugin or server's issue.
    Also, I tried to activate back your current theme and activated the Easy SMTP plugin and again I got only one email. So, it means there isn't a conflict with the theme or that plugin there.
    You need to activate each plugin one after the other in turn from Plugins -> Recently Active list and repeat this test again.
    Or you can contact support of your hosting provider about this issue. Maybe they have some logs about sending emails or something else.

    Best,
    Ivan.

  • David @ BBS

    Hi Ivan,

    So bad news, unfortunately I'm not able to replicate your "I got email and it was once" success. I ultimately switched back to the 2017 theme to do more testing. And by more testing I mean I spent 2 days on testing every possible scenario...

    Right now the randomness of the message deliveries is out of this world. Sometimes it's one to the client and two to the service provider, other times it can be 3 to each one. There doesn't seem to be ANY consistency regarding that.

    I tried 3 different SMTP plugins:
    -Easy WP SMTP
    -Gmail SMTP
    -WP Mail SMTP

    Neither one of them provided any more consistency than any other.

    I also tested it under PHP 5.6 and 7.0.25. Both versions have exactly the same issues.

    I even rolled back the Appointments+ plugin to v 2.2.2.2, the problem was the same. So rolled back to your patched version of 2.2.3.

    In each case I would not do 1 test, but I'd setup between 6-10 different appointments to see how they behave.

    The only thing that has improved is that your patch has stopped additional logs from appearing. But the duplicate emails are still being sent. :slight_frown:

    The good news is I've noticed two additional bugs. Maybe one of them can lead us in the direction of the true problem?

    1. If I try to access pages of the site around the same time that the reminder emails are being sent out I frequently get a fatal error:
    Fatal error: Call to undefined method Google_Client::getClassConfig() in /wp-content/plugins/appointments/includes/external/google/Logger/Abstract.php on line 126

    Could the Google library be outdated and have bugs?

    2. Additionally, I noticed that the CLIENT placeholder is almost never replaced with the actual client name in the reminder emails.

    Thoughts?
    I'm curious to hear what you think and how we can resolve this...

    Thanks!
    David

  • David @ BBS

    I noticed that the "Service Providers" Settings Page wouldn't update changes and instead generated a PHP error "Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini". I realized that this was most likely happening due to the amount of service providers we have. I managed to get that fixed by updating the max_input_vars to 8000. Everything saves great on the settings page again. I also updated to the latest Appointments+ Plugin v2.2.4. I was hoping that maybe the update and the max_input_vars change together would resolve the email problem, but unfortunately no. All of the above errors and problems are still happening.

    On PHP 7.0.25 the Google Client fatal error looks like this:

    Fatal error: Uncaught Error: Call to undefined method Google_Client::getClassConfig() in /wp-content/plugins/appointments/includes/external/google/Logger/Abstract.php:126 Stack trace: #0 /wp-content/plugins/appointments/includes/gcal/class-app-gcal-logger.php(6): Google_Logger_Abstract->__construct(Object(Google_Client)) #1 /wp-content/plugins/appointments/includes/gcal/class-app-gcal-api-manager.php(58): Appointments_Google_Calendar_Logger->__construct(Object(Google_Client)) #2 /wp-content/plugins/appointments/includes/gcal/class-app-gcal-api-manager.php(43): Appointments_Google_Calendar_API_Manager->get_client() #3 /wp-content/plugins/appointments/includes/class-app-gcal.php(71): Appointments_Google_Calendar_API_Manager->__construct() #4 /wp-content/plugins/appointments/includes/class-app-gcal.php(62): Appointments_Google_Cal in /wp-content/plugins/appointments/includes/external/google/Logger/Abstract.php on line 126

    I am really looking forward to hearing your thoughts and suggestions.

  • Ivan

    Hi David @ BBS !

    Thank you for investigating this issue and providing us a lot of details.

    1. I frequently get a fatal error:
    Fatal error: Call to undefined method Google_Client::getClassConfig()

    It happens because Appointments+, Gmail SMTP, WP Mail SMTP and Backupbuddy plugins use the same Google_Client library on your site but with different its versions. The first included library blocks including other ones and it tries to call the method which exists in our version but doesn't exist in the included version. This issue shouldn't happen again after deactivation of those plugins.

    2. Additionally, I noticed that the CLIENT placeholder is almost never replaced with the actual client name in the reminder emails.

    Did you create those appointments via Admin area? If so - you should set client name in the following field

    In other cases - new clients also set their names or it automatically does for existing clients from User area.

    I tested the current issue on your test2 site again and I did it 5 times and I get only one email each time. Do you use gmail for your test clients? Maybe you changed something and resolved this issue?
    Also, if you see one line in your logs and get several the same emails - it means that it doesn't apply our code several times and it's a good news. On the other hand, it means that the problem is in email sending. Did you test it without SMTP plugins at all? Only using Default WP Mail?

    Best,
    Ivan.

  • David @ BBS

    Hi Ivan!

    Thanks for being willing to keep investigating this.

    Thanks for the great feedback on the two issues. Regarding the Google Client error, another one of your colleagues posted a workaround here yesterday: https://premium.wpmudev.org/forums/topic/appointments-conflict-1#post-1300823
    I implemented the workaround on the Test site you're working on and it definitely made the errors go away. So that's nice.

    As for the double emails, I am still getting them almost every single time. In fact last night when I ran a test, both the client and the service provider received 2 emails for one appointment. The client email address is hosted on G Suite. The service provider email is a standard Gmail account.

    Before I even started testing SMTP plugins, I had tested without any SMTP plugin as well. Same results. :disappointed:

    So it's still an issue.

  • David @ BBS

    Ivan!
    Great news: this definitely fixed the double sending of notifications! So everyone is now receiving a single reminder notification email. :slight_smile:
    Thanks for the awesome detective work! Is this a fix that I'll need to apply manually each time or will it be added to an upcoming update of the plugin?

    I created 6 appointments. The service provider received 6. The client however only got 5. Appointment 638 didn't send a reminder to the client. And the logs confirm that. Any idea why this may be?

    Cheers!

  • Ivan

    Hi David @ BBS !

    Thank you for your help too.

    So, it looks like one more bug :slight_smile: It seems it happens when it tries to send several reminders at the same time. I deleted the following line from wordpress_folder/wp-content/plugins/appointments/includes/notifications/class-app-notification-reminder.php file via FTP (approximately 68th line)
    $sent_once = true;
    It should help.
    Also, I'll implement these both changes to the next version of the plugin.

    Best,
    Ivan.

  • David @ BBS

    Ivan,

    I did a TON of testing over the last two days and here's what I found:

    The GREAT NEWS:
    If the website is actively being used, the current updates you made to the code send only one email reminder to all the parties involved. Regardless if I have one appointment or multiple to send out for a specific time slot. Everyone get's one email. So yay!

    THE BAD NEWS:
    However, if I create a bunch of appointments and don't visit the site for the next half day, on next visit every single email gets sent out. But DOUBLE. And the logs confirm that. Check out the logs for appointments 675 through 682. Each email reminder was sent twice to the client and twice to the service provider.

    Also, when trying to load the website after so many hours, it took 30 seconds to load as all the emails were sending out. Which got me inspecting the code and I realized that none of the emails are being sent using WP Cron. Which significantly extends the page load times. :disappointed: Is there a specific reason why you don't use wp-cron for this task within Appointments+ and the Membership plugin?

    On a side note, interestingly enough, while visiting each page of the site to get the notification emails to send out, the emails don't get sent till 7 minutes after they should have gone out. Curious what that's about as well...

    Looking forward to your reply!
    David

  • Ivan

    Hi David @ BBS !

    Also, when trying to load the website after so many hours, it took 30 seconds to load as all the emails were sending out. Which got me inspecting the code and I realized that none of the emails are being sent using WP Cron. Which significantly extends the page load times.

    For avoiding it - you can follow this article https://www.siteground.com/tutorials/wordpress/real-cron-job/ . And use home URL instead of URL to the wp-ajax page there. It will look like your site has activity and it will send that emails more regularly.

    Is there a specific reason why you don't use wp-cron for this task within Appointments+ and the Membership plugin?

    As for Appointment+, the reason is maybe to filter time period for updates. By default, it's 600. If you need it - you can change this value with help the app_update_time filter.
    By the way, what functionality from the Membership plugin do you mean?

    On a side note, interestingly enough, while visiting each page of the site to get the notification emails to send out, the emails don't get sent till 7 minutes after they should have gone out. Curious what that's about as well...

    As I mentioned above it's the time period for updates. You see 7 minutes - but it's a random number from 0 to 600 seconds (if you didn't change this value ). So, by default, it runs once in 10minutes or more (if your site don't have enough activity)

    However, if I create a bunch of appointments and don't visit the site for the next half day, on next visit every single email gets sent out.

    Thank you, for this test, it's very weird, especially different time into duplicated entities of the log. I need more time to investigate it. When I'll get more information about it - I let you know.

    Best,
    Ivan.

  • David @ BBS

    Thanks Ivan. I appreciate your help on this. Looking forward to hearing what you find!

    As for the topic of Cron, let me explain better. A brief explanation of how WP-Cron works, (from https://code.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress--wp-23119 )

    On every page load, WordPress checks if there is a need for WP-Cron to run. If there is a need, then it tries to make a request over HTTP to the wp-cron.php file. The reason to call wp-cron.php is because some jobs might take more time and the user requesting the WordPress page cannot be made to wait. Calling the wp-cron.php helps keep the WP-Cron function running as a separate process in the background without delaying the page load time for the user. Once the WP-Cron function starts, it continues to run until all the required jobs are completed or until it reaches an execution time as set in the server configuration.

    What I found is that neither the Appointments+ or Memberships plugin use the actual WP-Cron to send out emails. They do it using their own functions that are triggered on each page load. What this means is that since they're part of the same page-load process, the page takes significantly longer to load. Which is why I think it would be better to have all email notifications use WP-Cron to be sent rather than being part of the actual page load for the user. I see that the WPMU DEV dashboard plugin uses WP-Cron to check for updates, notifications and other elements, which doesn't delay load times, so I would think it would make sense to implement the same for Appointments+ and Memberships as well. Thoughts?

    Best,
    David

  • David @ BBS

    Ivan, glad to hear you've been making some awesome progress in it. Yay Cron! :smiley:
    Good news, cron seems to work really nice.

    I ran an identical set of two tests:
    -First I created a series of appointments with reminders to be sent out while actively browsing the site. These delivered great. One for each person.
    -Next I created a series of appointments to be sent out together after an extended time of not using the site. This one had mixed results. Although this time everything was delivered once (so yay for progress!), reminders for appointments 691 and 694 were never sent out. And the logs confirm that.

    Browsing through the logs I found this:
    PHP Notice: Trying to get property of non-object in {wordpress_folder}/wp-content/plugins/appointments/includes/class-app-ajax.php on line 111
    Could it be a clue?

    On a side note, I see that you defined 4 constants in Wp-Config. PLEASE be careful and only update things in the Test2 folder. You updated all three Wordpress installations on the server, including the live site, and in all three cases accidentally placed the constants after the following line:

    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

    which broke all three sites with fatal errors as the constants were being redefined in the wrong place with attempts to resend headers, etc. I have fixed the placement, so they now work well. I know that this was a simple mistake, but just to make sure that our live site doesn't go down again, please only make modifications in the "test2" folder. We can play and break things as much as we want there. :slight_smile: Thanks a lot!!

  • Ivan

    Hi David @ BBS !

    It seems I didn't change the wp-config.php file on your site at all and I definitely couldn't add something after that line because we should add some changes only before this line
    /* That's all, stop editing! Happy blogging. */
    By the way, I noticed that someone moved this line to the end of the file. This line should be before this code

    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )

    Of course, it's only a comment line and it doesn't break something. Ok, let's move on.
    As I noticed the 691 and 694 appointments were finished at 13:50 and 15:30, cron was running at 15:32 - so it doesn't send reminders for completed appointments.

    Best,
    Ivan.

  • David @ BBS

    Ah, fair enough. I re-tested and all emails were delivered perfectly! Thank you for the incredible detective work Ivan!

    I assume all these changes will make it into the next Appointments plugin update?
    Minus the line:
    error_log( 'run the cron' );

    To my knowledge, in the end the files that were modified included:

    class-app-notifications-manager.php
    class-app-notification-reminder.php
    class-app-notification-notification.php

    Does that sound right?

  • Ivan

    Hi David @ BBS !

    Thank you!
    I'm not sure that it will be able to be in the next release (maybe through one) because these changes are in the testing step now.
    Also, there are changes in the appointments.php and uninstall.php files there too (in general removing old functionality for sending reminders). By the way, what do you mean about class-app-notification-notification.php changes? It seems this file wasn't changed, wasn't it?

    Best,
    Ivan.

  • Ivan

    Hi David @ BBS !

    For uninstall.php it's only one things for adding the WP Cron schedule if it's not added yet.
    After this line (approximately 70th line)
    wp_unschedule_event( current_time( 'timestamp' ), 'appointments_gcal_sync' );
    it was added this code

    if ( $timestamp = wp_next_scheduled( 'appointments_send_reminders' ) ) {
        wp_unschedule_event( $timestamp, 'appointments_send_reminders' );
    }

    And for appointments.php file - actually, there is nothing important after changing this functionality to WP Cron. So, never mind :slight_smile:

    Best,
    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.