Skip to main content
 Web开发网 » 站长学院 » Wordpress教程

WordPress投稿功能添加邮件提醒功能

2021年07月13日6420百度已收录

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

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

  // 其中 ludou_tougao_email 是自定义栏目的名称

  add_post_meta($status, 'ludou_tougao_email', $email, TRUE);

  二、添加提醒功能php代码

  在主题目录下的functions.php(改成你自己的):

  function tougao_notify($mypost) {

  $email = get_post_meta($mypost->ID, "ludou_tougao_email", true);

  if( !empty($email) ) {

  // 以下是邮件标题

  $subject = '您在露兜博客的投稿已发布';

  // 以下是邮件内容

  $message = '

  <p><strong>露兜博客</strong> 提醒您: 您投递的文章 <strong>' . $mypost->post_title . '</strong> 已发布</p>

  <p>您可以点击以下链接查看具体内容:<br />

  <a href="' . get_permalink( $mypost->ID ) . '">点此查看完整內容</a></p>

  <p>===================================================================</p>

  <p><strong>感谢您对 <a href=";

  <p><strong>该信件由系统自动发出, 请勿回复, 谢谢.</strong></p>';

  add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));

  @wp_mail( $email, $subject, $message );

  // 当投稿的文章从草稿状态变更到已发布时,给投稿者发提醒邮件

  add_action('draft_to_publish', 'tougao_notify', 6);  以上功能需要你的服务器支持mail函数。

评论列表暂无评论
发表评论
微信