str_replace(): Argument #3 ($subject) must be of type array|string, null given

When i try to send est mail, it showing the attached error, i upgraded to 2.0.11

str_replace(): Argument #3 ($subject) must be of type array|string, null given​

 

Attachments

  • error.PNG
    error.PNG
    22.8 KB · Views: 9
I had this same issue now with the latest Mailwizz version, it was caused by the RANDOM_CONTENT tag not being able to render numbers randomly (it used to be able to in earlier versions)
 
@rita - I just tried now and I cannot reproduce it:
Code:
$content = 'This is some random content "[RANDOM_CONTENT: 1|2|3|4|5]" and it should work just fine!';

echo CampaignHelper::applyRandomContentTag($content) . PHP_EOL;
And I got:
Bash:
cristi@Serbans-MacBook-Pro /tmp % php rnd.php     
This is some random content "2" and it should work just fine!
cristi@Serbans-MacBook-Pro /tmp % php rnd.php
This is some random content "5" and it should work just fine!
cristi@Serbans-MacBook-Pro /tmp % php rnd.php
This is some random content "3" and it should work just fine!
Can you please give me more details?
 
I have the same issue. Something like [RANDOM_CONTENT:220|205|235] returns:

Error 500!​

str_replace(): Argument #3 ($subject) must be of type array|string, int given​


Was there a fix for this?
 
@kevinb77 can you please open /apps/common/components/helpers/CampaignHelper.php and at line 2157 you have:
PHP:
$content  = (string)str_replace($tag, $tagValue[$randKey], $content);
make it:
PHP:
$content  = (string)str_replace($tag, $tagValue[$randKey], (string) $content);
Save the file and try again, same error?
 

I implemented the $content = (string)str_replace($tag, $tagValue[$randKey], (string) $content); and still got the error. Here's the debug info:

TypeError

str_replace(): Argument #3 ($subject) must be of type array|string, int given
/var/www/html/apps/common/components/utils/EmailTemplateTagFilter.php(59)
47 * @return string

48 */
49 public function apply(string $content, array $registeredTags = []): string
50 {
51 $filtersMap = $this->getFiltersMap();
52
53 $searchReplace = [];
54 foreach ($registeredTags as $tagName => $tagValue) {
55 //if (empty($tagValue)) {
56 // continue;
57 //}
58
59 $tagName = (string)str_replace(['[', ']'], '', $tagName);
60 if (strpos($content, '[' . $tagName . ':filter:') === false) {
61 continue;
62 }
63
64 // do we really need preg_quote ?
65 if (preg_match_all('/\[' . preg_quote($tagName, '/') . ':filter:([a-z0-9|,\(\)\s\p{L}&;#]+)\]/iu', $content, $matches)) {
66 if (empty($matches[1])) {
67 continue;
68 }
69
70 $filterTags = array_unique($matches[0]);
71 $filterStrings = array_unique($matches[1]);


Stack Trace

/var/www/html/apps/common/components/utils/EmailTemplateTagFilter.php(59): str_replace()
54 foreach ($registeredTags as $tagName => $tagValue) {
55 //if (empty($tagValue)) {
56 // continue;
57 //}
58
59 $tagName = (string)str_replace(['[', ']'], '', $tagName);
60 if (strpos($content, '[' . $tagName . ':filter:') === false) {
61 continue;
62 }
63
64 // do we really need preg_quote ?
/var/www/html/apps/common/components/helpers/CampaignHelper.php(49): EmailTemplateTagFilter->apply()
44 $content = StringHelper::decodeSurroundingTags($content);
45 $content = HtmlHelper::fixDragAndDropBuilderMarkup($content);
46
47 $searchReplace = self::getCommonTagsSearchReplace($content, $campaign, $subscriber, $server);
48 $content = (string)str_replace(array_keys($searchReplace), array_values($searchReplace), $content);
49 $content = self::getTagFilter()->apply($content, $searchReplace);
50
51 $to = $searchReplace['[CAMPAIGN_TO_NAME]'] ?? '';
52 $subject = $searchReplace['[CAMPAIGN_SUBJECT]'] ?? '';
53
54 // tags with params, if any...
/var/www/html/apps/customer/controllers/CampaignsController.php(2059): CampaignHelper::parseContent()
2054 if (!$onlyPlainText && CampaignHelper::hasCountdownTag($emailContent)) {
2055 $emailContent = CampaignHelper::parseCountdownTag($emailContent, $campaign, $subscriber, $server);
2056 }
2057 //
2058
2059 $emailData = CampaignHelper::parseContent($emailContent, $campaign, $subscriber, false, $server);
2060 [, $_emailSubject, $emailContent] = $emailData;
2061
2062 // since 1.3.5.3
2063 if (CampaignHelper::contentHasXmlFeed($_emailSubject)) {
2064 $_emailSubject = CampaignXmlFeedParser::parseContent(

[td width="2em"]
#0

[/td]
[td width="2em"]
#1

[/td]
[td width="2em"]
#2

[/td]​
 
Okay, in this case the filter is simple, open /apps/common/components/utils/EmailTemplateTagFilter.php and at line 59 you have:
Code:
$tagName = (string)str_replace(['[', ']'], '', $tagName);
Make it:
Code:
$tagName = (string)str_replace(['[', ']'], '', (string) $tagName);
Save and try again, it should work. But it is a bit weird you get this error, the tag name should always be a string, not sure how it ends up being a integer.
 
Back
Top