Scheduled Emails & Timezone - Understanding & Strange Behaviours

Your software
My Mautic version is: 4.4.4
My PHP version is: 7.4

Your problem
My problem is:

When you have a campaign with a Send Email scheduled for a specific time like 7pm UTC, it is not sent to all the users at 7pm UTC.

So some investigation and points to note. After realizing that certain users are getting the emails at the wrong time we started diving into this to understand what is going on here.

  1. We checked the systematize some on the server and verified it is set to UTC. This is important for your cronjob as they will run according to system time.
  2. We checked the TimeZone of the user that is logged in and verified that their timezone is set inside Mautic to UTC. If it is not set to UTC, but rather another time zone, the email will be sent out at the users time zone regardless of what Mautic default timezone is set to.
  3. Verified that timezone in php.ini is set to UTC.

Then we went and setup a campaign with an action to send an email at 5pm UTC (for example).
Added a bunch of users to the campaign, updated the campaign and triggered the campaign.
Went to inspect the users contact cards and noticed that some users had events scheduled to 5pm UTC but others had the same event scheduled for different UTC times… This seemed strange.

Opened user cards and noticed that certain users did not have “Preferred Timezone” set and some did.
For those without “Preferred Timezone” the message where scheduled to go out at specified time UTC, however for the ones that had it set their scheduled send time was different and not conforming to time change conversions.

For example:
User TimeZone set to Jerusalem/Israel, the mail is scheduled to go out at 2am UTC. Israel is +3 UTC, so it should really be scheduled to go out at 8am.
User TimeZone set to America/New_York, the mail is scheduled to go out at 9am UTC. America/New_York is UTC -4, so this should go out at 1am

It looks like my understanding of the logic here is a bit backwards, so maybe someone can shed some light on the matter (@joeyk :wink: ).

Next question is how and when is the Preferred TimeZone set because I see it for some users and not for others.

bumping this up with the hope that someone can chime in here. Is there anyway to override the timezone settings for all contacts so that it does not get updated?

Hi Mike, does this comment clarify something?

Note: I used at first UTC inside Mautic. This was wrong, as this one does not consider Summer-Time. I changed to Berlin and it works ok.

Hi @IonutOjicaDe thanks for the reply. Yes I understand the current behaviour and how Mautic is dealing with both user and contact timezone, what I am looking to see if there is a way to override the preferred timezone as we would like all RSS emails going out at a specific UTC time irrespective of the contacts timezone.

Well it drove me mad, but finally found how to comment this setting out and stop the system from sending at contacts preferred timezone (if set).

In order to remove the sending of an email to a contact at his preferred timezone, need to do the following:

  1. Make a copy of the file before doing anything
  2. Edit file /var/www/mautic/app/bundles/CampaignBundle/Executioner/Scheduler/Mode/Interval.php
  3. Comment out lines 245 through to 262

Here is the code block:

  // Set execution to UTC
        if ($timezone = $contact->getTimezone()) {
            try {
                // Set the group's timezone to the contact's
                /** Commented out in order to remove sending at contacts preferred timezone 
                $contactTimezone = new \DateTimeZone($timezone);

                $this->logger->debug(
                    'CAMPAIGN: ('.$eventId.') Setting '.$timezone.' for contact '.$contact->getId()
                );

                // Get now in the contacts timezone then add the number of days from now and the original execution date
                $groupExecutionDate = clone $compareFromDateTime;
                $groupExecutionDate->setTimezone($contactTimezone);

                $groupExecutionDate->add($diff);

                $groupExecutionDate->setTime($groupHour->format('H'), $groupHour->format('i'));

                return $groupExecutionDate;
                **/
            } catch (\Exception $exception) {
                // Timezone is not recognized so use the default
                $this->logger->debug(
                    'CAMPAIGN: ('.$eventId.') '.$timezone.' for contact '.$contact->getId().' is not recognized'
                );
            }
        }

1 Like

Hey, great workaround ! Thank you for your tip.

Of course, it would be better if each email (segment or campaign email) could have a boolean setting: according to contact timezone or to owner timezone.

But, until then, how could we achieve this one? Let’s say, if we include a specific text inside “Internal Name” of the email that we can check in the code and act accordingly?

Later edit:
Here ist the Feature request:

@tobsowo @mikew : Please vote :slight_smile:

Maybe create a feature request.

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.