首页 > 解决方案 > wp_mail 退订链接

问题描述

我正在使用 wp_mail 功能向我的订阅者发送时事通讯模板。我只是从我的数据库中检索我的订阅者列表并将其作为 $to 的数组传递给 wp_mail 函数。现在的问题是,我想在我的电子邮件中添加取消订阅链接。我想要实现的只是一种在我的取消订阅的超链接中添加收件人的电子邮件地址作为参数的方法,以便我可以将其用于取消订阅。即 www.mysiteurl.com/?user_email=useremail@domain.in

//php code
ob_start();
    //including newsletter template
    include '/newsletter-template.php';
    $message = ob_get_contents();
    ob_end_clean();
    //adding filter to allow <html> tags in message body
    add_filter( 'wp_mail_content_type', 'newsletter_content_type' );
    @wp_mail( $subscriberListArray, 'Testing Newsletter', $message, 'From: myWebsite <newsletter@myWebsite.com>' );
    //removing <html> tags filter once mail is sent
    remove_filter( 'wp_mail_content_type', 'newsletter_content_type' );

//html part
<div>
  <a href="www.mysiteurl.com/?user_email={dynamic_value}">unsubscribe</a>
</div>

上面的代码工作正常,但我想在我的模板文件中插入当前订阅者的电子邮件。有什么办法吗?谢谢你。

标签: phpwordpressnewsletter

解决方案


推荐阅读