[Solution] Newsletter Can't Be Sent Due To Php Error


I haven't been able to send newsletters for some time and upgraded the store from 4.6.x to 4.9.3 but the problem didn't go away. I checked the error logs and saw this;

PHP Warning: preg_replace_callback(): Compilation failed: invalid range in character class at offset 37 in /var/www/vhosts/example.com/httpdocs/app/addons/newsletters/func.php on line 117

Appearently, PCRE version has changed in PHP 7.3 and some regular expressions were rendered invalid thereafter.

I opened the mentioned file, found this line;

$regex = "/href=('|\")((?:http|ftp|https):\/\/[\w-\.]+[?]?[-\w:\+?\/?\.\=%&;~\[\]]+)/i";

Replaced with;

$regex = "/href=('|\")((?:http|ftp|https):\/\/[\w\-\.]+[?]?[-\w:\+?\/?\.\=%&;~\[\]]+)/i";

As you will notice, I escaped the dash ( - ) because after PHP 7.3, dashes that don't define a range needs to be escaped. Now I can send newsletters.

By the way, the same problem effects some other places in CS Cart as well.

Please post this to the bug tracker so that CS-Cart team pay attention to the issue

PHP 7.3 isn't supported by CS-Cart yet

Seems so; I thought I saw it in the changelog and it turns out that CS Cart supported PHP 7.2 in version 4.9.2 and not PHP 7.3. But it also seems that 4.10.x versions support PHP 7.3. Haven't checked if this compatibility issue is present in 4.10.x yet but according to the 4.10.1 changelog, PHP 7.3 is de facto supported already.