Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafiahmedd/21c2f3f71aecd965878c4b52f4c9302c to your computer and use it in GitHub Desktop.
Save rafiahmedd/21c2f3f71aecd965878c4b52f4c9302c to your computer and use it in GitHub Desktop.
Email to Admin After User Unsubscribe From CRM With Unsubscribe Reason
add_action('fluentcrm_subscriber_status_to_unsubscribed', 'emailAfterUnsubscribed', 10, 2);
function emailAfterUnsubscribed($subscriber, $oldStatus){
$req = FluentCrm('request');
$reason = sanitize_text_field($req->get('reason'));
if ($reason == 'other') {
if ($otherReason = $req->get('other_reason')) {
$reason = sanitize_text_field($otherReason);
}
} else if($reason){
if ( method_exists('ExternalPages', 'unsubscribeReasons' ) ) {
$reasons = ExternalPages::unsubscribeReasons();
if (isset($reasons[$reason])) {
$reason = sanitize_text_field($reasons[$reason]);
}
}
}
$email = $subscriber->email;
$first_name = $subscriber->first_name;
$to = 'admin@mail.com'; //Your mail id you call also email to the user
$subject = $first_name.' unsubscribed form your site.';
$message = $email.' unsubscribed the reason behind it is: '.$reason;
return wp_mail( $to, $subject, $message );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment