优选主流主机商
任何主机均需规范使用

如何在WordPress投稿系统中实现邮件提醒功能

一、添加一个存储投稿者邮箱的自定义栏目

打开WordPress添加投稿功能,下面我们将对这篇文章中的代码进行修改。在第二段代码第78行插入以下代码:

  1. // 其中 ludou_tougao_email 是自定义栏目的名称
  2. add_post_meta($status, ‘ludou_tougao_email’, $email, TRUE);

二、添加提醒功能php代码

在主题目录下的functions.php添加以下php代码(将以下代码中的露兜博客名称和URL改成你自己的):

  1. function tougao_notify($mypost) {
  2.     $email = get_post_meta($mypost->ID, “ludou_tougao_email”, true);
  3.     if( !empty($email) ) {
  4.         // 以下是邮件标题
  5.         $subject = ‘您在露兜博客的投稿已发布’;
  6.         // 以下是邮件内容
  7.         $message = ‘
  8.         <p><strong>露兜博客</strong> 提醒您: 您投递的文章 <strong>’ . $mypost->post_title . ‘</strong> 已发布</p>
  9.         <p>您可以点击以下链接查看具体内容:<br />
  10.         <a href=”‘ . get_permalink( $mypost->ID ) . ‘”>点此查看完整內容</a></p>
  11.         <p>===================================================================</p>
  12.         <p><strong>感谢您对 <a href=”https://www.jb51.net” target=”_blank”>露兜博客</a> 的关注和支持</strong></p>
  13.         <p><strong>该信件由系统自动发出, 请勿回复, 谢谢.</strong></p>’;
  14.         add_filter(‘wp_mail_content_type’,create_function(”, ‘return “text/html”;’));
  15.         @wp_mail( $email, $subject, $message );
  16.     }
  17. }
  18. // 当投稿的文章从草稿状态变更到已发布时,给投稿者发提醒邮件
  19. add_action(‘draft_to_publish’, ‘tougao_notify’, 6);

以上功能需要你的服务器支持mail函数。

未经允许不得转载:搬瓦工中文网 » 如何在WordPress投稿系统中实现邮件提醒功能