如何通过wordpress中的电子邮件通知

时间:2018-03-05 19:43:03

标签: wordpress

当访问者点击此链接被按下的链接和/或用户ip,城市和国家是这样时,如何通过wordpress通过电子邮件通知? 我已经为该链接提供了一个'电子邮件链接'。

2 个答案:

答案 0 :(得分:0)

由于链接是HTML并且与WordPress直接控制或处理的任何内容无关联或集成,因此您不能将此作为WordPress的直接后果。 WordPress只是一个结构/进程,通过它您可以向数据库添加信息,然后再检索它。

如果你的问题实际上是指一个更通用的,而不是具体的wordPress意义,那么答案是多种方式。例如,您可以创建一些JQuery或JS,以便在每次单击链接时添加该信息。但是,您需要与页眉进行交互以尝试获取所有必需的信息。

但是,当一个免费的&可以说市场领先的工具已经可以实现吗?

这个过程的逻辑过程是使用Google Analytics(或竞争对手的工具),因为这已经收集了这种信息,只需要很少的工作来设置它。如果您想要更具体的“事件”触发数据(例如点击链接),那么您也可以相当容易地做到这一点。

https://analytics.google.com

<强> 更新

在您的评论中,您明确表示您希望在点击链接时向您发送实时电子邮件,因此分析不符合要求。在这种情况下,您需要使用JQuery&amp; amp; AJAX。

简单来说,你需要做一些事情:

1)创建一些JQuery来拦截点击链接的URL

2)通过AJAX调用将链接(和标题信息)传递给函数

3)处理标题数据/发送电子邮件

4)将用户重定向到从链接传递的网址

以下是在WordPress中创建简单AJAX流程的教程:https://www.makeuseof.com/tag/tutorial-ajax-wordpress/

答案 1 :(得分:0)

这样的事情应该让你开始

// functions.php
// HTML form markup
function mail_form_stuff() {
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
    echo '<p><input type="submit" name="send_the_email_to_admin" value="Click this button"></p>';
    echo '</form>';
}

// make sure the email will allow for html -- not just plain text
add_filter( 'wp_mail_content_type', 'send_the_email_to_admin_content_type' );
function send_the_email_to_admin_content_type() {
  return 'text/html';
}

// if the button is clicked, send the email
function deliver_mail_link_stuff() {
  $admin_email = get_option( 'admin_email' );
  if ( isset($_POST["send_the_email_to_admin"]) ) {
    $_user = wp_get_current_user();
    $_name = esc_html( $_user->user_firstname );
    $_email = esc_html( $_user->user_email );

    $to = $admin_email;
    $subject = "Some person clicked my link";
    $message = 'Hey this person clicked on that button'.'<br>';
    $message .= "the persons email address was: $_email";

    $headers[] = "From: $_name <$_email>" . "\r\n";
    // $headers[] = "Bcc: John Smith <jsmith@gmail.com>" . "\r\n";

    // If everything worked -- display a success message
    if ( wp_mail( $to, $subject, $message, $headers ) ) {
        echo '<p>sent</p>';
    } else {
        echo 'An unexpected error occurred';
    }
    // reset wp_mail_content_type
    remove_filter( 'wp_mail_content_type', 'send_the_email_to_admin_content_type' );
    }
}

function add_short_code_stuff() {
    ob_start();
    deliver_mail_link_stuff();
    mail_form_stuff();
    return ob_get_clean();
}
add_shortcode( 'EMAIL_BUTTON', 'add_short_code_stuff' );

这将为您添加一个简短的代码

然后您可以使用

调用主题中的短代码
echo do_shortcode('[EMAIL_BUTTON]');