Home › Forums › General Issues › Email sent when connect button pressed
Hi all,
I have a button on an author page which is currently forcing an addition of a user to a user field (like a follow/connect button), it doesn’t really do much other than that. It just adds the author you’re currently on, to an ACF field in your logged in users account.
What i’m needing to do, is have an email send to the author when the user presses the connect button to say, someone has connected to you.
Is there a way to achieve this simply. It doesn’t need to be overly complex.
This is the code that i’m using for the button functionality:
<?php
$profile_user = get_queried_object();
$current_user = wp_get_current_user();
$current_user_slug = 'user_' . $current_user->ID;
$field_key = "field_63d0017ab088f";
$user_likes = [];
if(get_field('user_follows', $current_user_slug)){
$user_likes = get_field('user_follows', $current_user_slug);
}
if(isset($_POST['follow'])){
if($_POST['follow'] === 'Disconnect'){
$key = array_search($profile_user, $user_likes);
unset($user_likes[$key]);
update_field($field_key, $user_likes, $current_user_slug);
}elseif($_POST['follow'] === 'Connect'){
$user_likes[] = $profile_user;
update_field($field_key, $user_likes, $current_user_slug);
}
}
$but_val = 'Connect';
if (in_array($profile_user, $user_likes)) {
$but_val = 'Disconnect';
}
?>
<form method="post">
<input type="submit" name="follow" value="<?= $but_val; ?>" style="display:inline-block;max-width:200px;">
</form>
If it could be fired only when someone presses to connect (not disconnect) that would be great.
Any help would be awesome 🙂
Chris
Just added this and am now waiting for my email to come through.. Fingers crossed:
$to = $profile_user->user_email;
$subject = 'Design4Health User Connection';
$body = 'Hi '.$profile_user->nice_name.',<br/><br>you have just been connected by '.$current_user->nice_name.' on Design4Health.<br/><br>Please log in to see your connections.<br/><br>If you would like this connection to be removed. Please contact [email protected] for further assistance.<br/><br>Kind Regards<br/><br>Design4Health' ;
$headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <[email protected]>');
wp_mail( $to, $subject, $body, $headers );
I put this within the elseif($_POST['follow'] === 'Connect'){
section
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.