Home Forums General Issues Email sent when connect button pressed


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:

        $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($_POST['follow'] === 'Disconnect'){
                $key = array_search($profile_user, $user_likes);
                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;">

    If it could be fired only when someone presses to connect (not disconnect) that would be great.

    Any help would be awesome 🙂


  • inside of your

    elseif($_POST['follow'] === 'Connect'){

    block, use the function wp_mail()

  • 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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.