I need to add a button in the profile.php pages for every user in the back-end, in order to send an email via php. I managed to do it correctly when I click the button in the profile user I'm logged into, but when I tried to do in other users, I got the wordpress error "Invalid user ID" I used the hooks show_user_profile and edit_user_profile correctly but I think there is some issue with the POST method. After this issue will be solved, I need to change dynamically the email with the user's email I'm into.
function fileEmailNotification(WP_User $user) {
?>
<h2>Invia notifica file</h2>
<?php
if(isset($_POST['submit']))
{
$to = 'XXX@email.it';
$subject = 'XXX';
$body = 'XXX';
$headers = 'Content-type: text/html;charset=utf-8' . "
";
$headers .= 'From: XXX <XXX@XXX.it>' . "
";
wp_mail( $to, $subject, $body, $headers );
echo "<script type='text/javascript'>alert('Email Sent');</script>";
}
submit_button('Invia notifica');
?> <form action="" method="post">
</form>
<?php
}
add_action('show_user_profile', 'fileEmailNotification');
add_action('edit_user_profile', 'fileEmailNotification');