spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

Campaign subject not used #178

Closed Propaganistas closed 4 years ago

Propaganistas commented 4 years ago

I'm on Mailcoach 2.11.3

I've configured a campaign with the following settings and I'm using Mailgun: Capture

Luckily I sent the campaign with a test list first, because apparently the set subject isn't retained:

Capture2

Seems to happen with both immediate and scheduled delivery. Test mails do use the set subject...

Propaganistas commented 4 years ago

Looking in the database, it seems the mailcoach_campaigns.subject column gets emptied, when sending a campaign...

EDIT: I just created a new campaign and launched sending while refreshing the database. The subject is indeed being emptied while the campaign is in "sending" status!

freekmurze commented 4 years ago

Verifying...

freekmurze commented 4 years ago

I'm trying to recreate the project using a test. Seems like this one is passing: https://github.com/spatie/laravel-mailcoach/blob/faf788b7ab96724a29a0e8bcca94222312281de9/tests/Jobs/SendCampaignJobTest.php#L88-L101

@Propaganistas Can you provide a failing test for me to fix. Will test in a real world app now...

freekmurze commented 4 years ago

I'm using v2.11.4 of mailcoach on freek.dev. There, using a custom subject seems to be working fine.

Screenshot 2020-05-07 at 16 03 47
freekmurze commented 4 years ago

O, noticed that you are using the test mail, not the actual campaign...

freekmurze commented 4 years ago

Seems test mail subject are working fine as well.

Screenshot 2020-05-07 at 16 08 23 Screenshot 2020-05-07 at 16 08 26
freekmurze commented 4 years ago

This test proves that the subject should be ok, even for a test mail: https://github.com/spatie/laravel-mailcoach/blob/305d23ae09a87786fd4f94b26d70c3f5b1db946f/tests/Jobs/SendTestMailJobTest.php#L31

I appreciate any tips on how to reproduce the problem you are seeing.

Propaganistas commented 4 years ago

I'm on a completely fresh install of Mailcoach 2.11.3. No fancy settings... Let's set up a call? I'll email you.

freekmurze commented 4 years ago

Unfortunately, I don't have time for a call atm. Could you try upgrading to the latest version?

Propaganistas commented 4 years ago

Okay got it. I did configure a custom replacer that merely substitutes a placeholder for the current year. Nothing too fancy, almost copy-paste from the docs.

But here's the catch. The docs are leading to this "bug":

https://mailcoach.app/docs/v2/package/advanced-usage/creating-custom-placeholders#creating-a-replacer

public function replace(string $html, Campaign $campaign): string
{
    $webviewUrl = $campaign->webviewUrl();

    return str_ireplace('::webviewUrl::', $webviewUrl, $campaign->email_html);
}

should be

public function replace(string $html, Campaign $campaign): string
{
    $webviewUrl = $campaign->webviewUrl();

    return str_ireplace('::webviewUrl::', $webviewUrl, $html);
}

It seems that performing substitution and returning $campaign->email_html again loses the subject somehow.

I guess this is sorted out. Sorry to make all the fuss, but I did everything by the book ;-) You might want to update your documentation.

freekmurze commented 4 years ago

Thanks for letting us know. The docs have been updated.