在自定义电子邮件 magento 中添加取消订阅链接

发布于 2024-11-09 13:29:34 字数 1750 浏览 0 评论 0原文

如何在自定义电子邮件通知中添加取消订阅链接 我正在通过 zend mail 功能发送电子邮件 我遵循此功能 发送邮件在 magento 的正文部分中,我想添加取消订阅链接,我们如何实现呢? 在我的电子邮件通知中我正在使用此功能。


public function sendMail()
    {           
        $post = $this->getRequest()->getPost();     
        if ($post){
                $random=rand(1234,2343);

                $to_email = $this->getRequest()->getParam("email");
                $to_name = 'Hello User';
                $subject = ' Test Mail- CS';
                $Body="Test Mail Code : "; 

                $sender_email = "[email protected]";
                $sender_name = "sender name";

                $mail = new Zend_Mail(); //class for mail
                $mail->setBodyHtml($Body); //for sending message containing html code
                $mail->setFrom($sender_email, $sender_name);
                $mail->addTo($to_email, $to_name);
                //$mail->addCc($cc, $ccname);    //can set cc
                //$mail->addBCc($bcc, $bccname);    //can set bcc
                $mail->setSubject($subject);
                $msg  ='';
                try {
                      if($mail->send())
                      {
                         $msg = true;
                      }
                    }
                catch(Exception $ex) {
                        $msg = false;
                        //die("Error sending mail to $to,$error_msg");
                }
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($msg));
            }
    }

How to add unsubscribe link in custom email notification i am sending an email through zend mail function i follow this function sending mail in magento in body part i want to add unsubscribe link how can we implement that?
In my e mail notification i am using this function.


public function sendMail()
    {           
        $post = $this->getRequest()->getPost();     
        if ($post){
                $random=rand(1234,2343);

                $to_email = $this->getRequest()->getParam("email");
                $to_name = 'Hello User';
                $subject = ' Test Mail- CS';
                $Body="Test Mail Code : "; 

                $sender_email = "[email protected]";
                $sender_name = "sender name";

                $mail = new Zend_Mail(); //class for mail
                $mail->setBodyHtml($Body); //for sending message containing html code
                $mail->setFrom($sender_email, $sender_name);
                $mail->addTo($to_email, $to_name);
                //$mail->addCc($cc, $ccname);    //can set cc
                //$mail->addBCc($bcc, $bccname);    //can set bcc
                $mail->setSubject($subject);
                $msg  ='';
                try {
                      if($mail->send())
                      {
                         $msg = true;
                      }
                    }
                catch(Exception $ex) {
                        $msg = false;
                        //die("Error sending mail to $to,$error_msg");
                }
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($msg));
            }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

oО清风挽发oО 2024-11-16 13:29:34

如果您有自定义模块,请使用以下代码:

Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getUnsubscriptionLink();

说明:

第一部分是订阅者的模型。
如果您想查看模型中的所有可用方法,只需使用以下代码:

$myModel =  Mage::getModel('newsletter/subscriber');
foreach (get_class_methods(get_class($myModel)) as $cMethod) {
    echo '<li>' . $cMethod . '</li>';
}

代码的第二部分loadByEmail($email) 是获取 1 个特定订阅者对象。 $email 应该是电子邮件地址的字符串。

代码的最后一部分是一个不言自明的方法。它将生成一个取消订阅的链接。这是Magento给出的方法。

If you have a custom module use this code:

Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getUnsubscriptionLink();

Explanation:

first part is the model for the subscriber.
If you want to see al the available methods within the model just use this code:

$myModel =  Mage::getModel('newsletter/subscriber');
foreach (get_class_methods(get_class($myModel)) as $cMethod) {
    echo '<li>' . $cMethod . '</li>';
}

the second part of the code loadByEmail($email) is to get 1 specific subscriber object. $email should be a string of the emailaddress.

The last part of the code is a selfexplaning method. It will generate a link to unsubscribe. This is a method that is given by Magento.

删除会话 2024-11-16 13:29:34

在我的 Magento 版本中,创建新的新闻通讯模板时,默认情况下会得到以下代码:

按照此链接取消订阅 {{varsubscriber.getUnsubscriptionLink()}}

我希望它可以在任何 Magento 版本中工作。

In my Magento version I get the following code by default when creating a new newsletter template:

Follow this link to unsubscribe <!-- This tag is for unsubscribe link --><a href="{{var subscriber.getUnsubscriptionLink()}}">{{var subscriber.getUnsubscriptionLink()}}</a>

I expect it to work in any Magento version.

安静被遗忘 2024-11-16 13:29:34

我正在使用 Magento 1.9。
要在新闻通讯模板中添加新闻通讯取消订阅链接,请执行以下步骤:

  1. 覆盖核心文件

/app/code/core/Mage/Newsletter/Model/Subscriber.php

通过复制到本地目录

/app/code/local/Mage/Newsletter/Model/Subscriber.php

  1. 在编辑器中打开以编辑代码并搜索 函数 sendConfirmationSuccessEmail()
    将此代码替换
$email->sendTransactional(
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
    $this->getEmail(),
    $this->getName(),
    array('subscriber'=>$this)
);

$email->sendTransactional(
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
    $this->getEmail(),
    $this->getName(),
    array('subscriber'=>$this, 'unsubscribe' =>$this->getUnsubscriptionLink())
);
  1. 并将此代码放置在您要使用取消订阅链接的电子邮件模板中:

    在此处取消订阅

就是这样!

希望这对某人有帮助。

I am using Magento 1.9.
To add newsletter unsubscribe link in newsletter template here are following steps:

  1. Override the core file

/app/code/core/Mage/Newsletter/Model/Subscriber.php

by copy in local directory

/app/code/local/Mage/Newsletter/Model/Subscriber.php

  1. Open in editor to edit the code and seacrh the function sendConfirmationSuccessEmail()
    replace the code
$email->sendTransactional(
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
    $this->getEmail(),
    $this->getName(),
    array('subscriber'=>$this)
);

with this

$email->sendTransactional(
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
    Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
    $this->getEmail(),
    $this->getName(),
    array('subscriber'=>$this, 'unsubscribe' =>$this->getUnsubscriptionLink())
);
  1. and place this code in email template where you want to use unsubscribe link:

    <a href="{{var unsubscribe}}">Unsubscribe here</a>

That's it!

Hope this helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文