Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with link and redirect #254

Open
ivang76 opened this issue Dec 10, 2024 · 7 comments
Open

issue with link and redirect #254

ivang76 opened this issue Dec 10, 2024 · 7 comments

Comments

@ivang76
Copy link

ivang76 commented Dec 10, 2024

Hi there,

I’ve been using your package for a while without any issues, on a Laravel 9 and PHP 8.1 environment.
Now I’ve updated to Laravel 11, PHP 8.3 and the latest version of your package (previously it was the 6), and I’ve noticed that when a user follows a link received in the newsletter, they are no longer redirected to the target URL. Instead, they always fall back to the home page of the web app.

For example, if in the newsletter I have a link like this:
https://mainurl.something/email/n?l=https://www.github.com/jdavidbakr...

when the user clicks on it, they end up at https://mainurl.something instead to reach your github page.

Do you have any advice on what to check and debug? Have you encountered anything similar with this configuration?
thanks!

update:
I'm debbuging the linkClicked function in your MailTrackerController.php and I notice that the tracker->domains_in_context is empty so the flow fail in the return redirect(config('mail-tracker.redirect-missing-links-to') ?: '/')
if I force a return redirect($url); the behaviour is correct.

I read something about the domains_in_context added to the SentEmail in a previous PR #248 by @mirkos93. In my project I needed to anonymize the recipient_email in the SentEmail model, could this create any problems?


class SentEmail extends Model
{

    protected static function booted()
    {
        static::saving(function ($sentEmail) {
           ...
           ...
           $sentEmail->recipient_email = $anonymizeEmail;
        }
    }
}
@mirkos93
Copy link

Hi @ivang76
From a quick analysis, it would appear that the problem lies in the regex in Model/SentEmail.php in the getDomainsInContextAttribute() attribute.
Could you provide the part in your HTML pertaining to the href link? The only problem in the regex I am noticing might be that it does not read single quotes. A test I recommend you do to remove this doubt is to use regex101.com to test HTML with regex.

@ivang76
Copy link
Author

ivang76 commented Dec 11, 2024

thanks for the prompt reaction @mirkos93

I'm checking the regex in the function you pointed out, to debug the regex, but I'm noticing a strange thing... the
$this->content when I click on a link of a newsletter for example, is empty... so of course the $matches[2] will be empty.
Any ideas?

(at the moment as I said I'm forcing that return redirect($url); to keep the whole project working as done until now)

@mirkos93
Copy link

Ciao @ivang76
have you by any chance already checked whether the whole $tracker variable is null? The problem is probably related to $hash not being found.
If $tracker is null and if you have a chance to do more tests, you should check if and how $hash is being valued and if this is found in the database.

If instead only $this->content is null (and thus is null or empty in the database as well) you probably need to take a closer look at the code where you anonymize the email addresses, I'm noticing that in your code you're not extending the SentEmail model (which in turn implements the IsSentEmailModel trait), maybe that's where the problem lies.

@ivang76
Copy link
Author

ivang76 commented Dec 11, 2024

thanks again @mirkos93

so, the $tracker is not empty and I extended the SentMail wiith something like this:

use jdavidbakr\MailTracker\Model\SentEmail as jdavidSentEmail;

class SentEmail extends jdavidSentEmail
{
  ...

but then I also removed temporary the anonymize function, but still it doesn't work.

I don't know, I'll try to do other debug but I'm a bit stuck now.

@ivang76
Copy link
Author

ivang76 commented Dec 12, 2024

@mirkos93 Indeed I'm noticing that the 'content' is null on all the newsletter sent, even in the older ones in the previous years.
Do you know where and how this field is set normally?
thanks

@ivang76
Copy link
Author

ivang76 commented Dec 15, 2024

I remembered, the content set to null is correct because stems from the log-content attribute in the configuration file, which I set to false years ago.
Because of this setting, your recent change for checking domains doesn't work, and now all the links have become unclickable. Could you please work on a fix for this?

@jdavidbakr
Copy link
Owner

You might be right, we may have to disable the click link tracker if you don't save the content since that was added for security reasons. If someone wants to submit a PR for that, please feel free to. I might be able to look at it but probably after the first of the year would be the soonest I'll get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants