Hello
I have created a newsletter template inside Magento 2.4.6 backend which will work except the unsubscribe link:
Template content:
<table style="background-color: #ffffe0; border-collapse: collapse; width: 600px;"> <tbody> <tr style="background-color: #0069b4; color: #ffffff; height: 40px; padding: 10px;"> <th class="tleft">Hotline: <a href="tel:+49123456789">+49 123 456 789 </a></th> <th class="tright"><a href="{{config path="web/secure/base_url"}}">SHOP.tld</a></th> </tr> <tr style="background-color: #ddd; border-top: solid 2px #808080; border-bottom: solid 2px #0069b4;"> <td class="tcenter" style="height: 40px;" colspan="2"> <ul> <li><a style="color: #575757;" href="{{config path="web/secure/base_url"}}link1">LINK1</a></li> <li><a style="color: #575757;" href="{{config path="web/secure/base_url"}}link2">LINK2</a></li> <li><a style="color: #575757;" href="{{config path="web/secure/base_url"}}sale">SALE</a></li> </ul> </td> </tr> </tbody> </table> <table style="background-color: #0069b4; border-collapse: collapse; width: 600px;"> <tbody> <tr style="color: #ffffff; height: 40px; padding: 10px;"> <td class="tcenter"> <p>Click on the link below tu unsubscribe from our newsletter:<br><a href="{{var subscriber.getUnsubscriptionLink}}">Unsubscribe</a></p> </td> </tr> </tbody> </table> <style type="text/css"> {{var template_styles|raw}} </style>
Template styles:
.tcenter { text-align: center; }
For sure it wont work in the preview but if I send a real newsletter it will also not work.
Any ideas.
thx opaque
Solved! Go to Solution.
Hello @opaque01
To fix this issue, you need to override the getUnsubscriptionLink() method in the Magento\Newsletter\Model\Queue class. You can do this by creating a new file called Queue.php in your Magento module. The following code will fix the issue:
<?php namespace Vendor\Module\Model; use Magento\Newsletter\Model\Queue; class Queue extends Queue { public function getUnsubscriptionLink() { $subscriber = $this->getSubscriber(); if ($subscriber) { $url = $this->getUrl('newsletter/subscriber/unsubscribe', ['id' => $subscriber->getId(), 'code' => $subscriber->getSubscriberCode()]); return $url; } return null; } }
Once you have created this file, you need to register it with Magento. You can do this by adding the following line to your module.xml file:
<module name="Vendor_Module" setup_version="1.0.0"> <sequence> <module name="Magento_Newsletter" /> </sequence> <files> <file name="Model/Queue.php" /> </files> </module>
After you have registered the file, you need to clear the Magento cache. You can do this by running the following command in a terminal window:
php bin/magento cache:flush
Once you have cleared the cache, the unsubscribe link in your newsletter template should now work.
Haven't worked on newsletter on Magento, but you can try adding this at the bottom of your email template, do let me know if it works.
<a href="{{var subscriber.getUnsubscriptionLink()}}"> {{var subscriber.getUnsubscriptionLink()}} </a>