我目前正在wordpress中处理一个项目,我需要一个php脚本,当用户单击按钮(重定向到脚本)时,它会向管理员(我)发送电子邮件,我希望电子邮件可以将以下数据发送给管理员:
- 用户名
- 此用户点击按钮时所在的帖子或网址
我一直在寻找一个插件几个小时,并在任何地方搜索脚本,我并不是最好的编码员,感谢您的帮助。
这是一个PHP代码片段,应该向您发送有关用户的页面和信息。
您可能需要安装 Wordpress PHP 插件才能插入此代码。https://wordpress.org/plugins/insert-php/
<?php
$email_body = '';
// Get the previous post
$previous_page = $_SERVER['HTTP_REFERER'];
$email_body .= 'Post or URL: ' . $previous_page . '<br />';
// Get the user information
$current_user = wp_get_current_user();
$email_body .= 'Username: ' . $current_user->user_login . '<br />';
$email_body .= 'User email: ' . $current_user->user_email . '<br />';
$email_body .= 'User first name: ' . $current_user->user_firstname . '<br />';
$email_body .= 'User last name: ' . $current_user->user_lastname . '<br />';
$email_body .= 'User display name: ' . $current_user->display_name . '<br />';
$email_body .= 'User ID: ' . $current_user->ID . '<br />';
// Send email
$to = 'you@gmail.com';
$subject = 'Button was clicked';
$message = $email_body;
wp_mail( $to, $subject, $message);
?>