• Resolved kooogi

    (@kooogi)


    Hi everyone,

    My question is, is it possible to send emial to old and new mail about change in a profile (address emial change). Now info about it goes only to new email address.

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • @kooogi

    Yes there is a code snippet where an email can be sent to the old address.

    https://docs.ultimatemember.com/article/66-check-when-user-updates-e-mail-via-account-page

    Thread Starter kooogi

    (@kooogi)

    add_action('um_account_pre_update_profile', 'send_custom_email_on_profile_change', 10, 2);
    function send_custom_email_on_profile_change($changes, $user_id) {
        $data = get_userdata($user_id);
    
        if (isset($changes['user_email']) && $data->user_email != $changes['user_email']) {
            $new_email = $changes['user_email'];
            $old_email = $data->user_email;
    
            // Load the template file
            $template_path = UM()->files()->plugin . 'ultimate-member/email/';
            $email_content = file_get_contents($template_path . 'changedaccount_email.php');
    
            // Replace placeholders with actual content
            $email_content = str_replace('{{new_email}}', $new_email, $email_content);
            $email_content = str_replace('{{old_email}}', $old_email, $email_content);
    
            // Send the email
            $to = array($new_email, $old_email);
            $subject = 'Zmiana adresu e-mail w profilu';
            $headers = array('Content-Type: text/html; charset=UTF-8');
            wp_mail($to, $subject, $email_content, $headers);
        }
    }

    I tried smth like this but it doesnt work

    @kooogi

    If you have localized the email template you will find the template via

    $template_path = STYLESHEETPATH . '/ultimate-member/email/';

    Email headers:

    $attachments = array();
            $headers = 'From: ' . stripslashes( UM()->options()->get( 'mail_from' ) ) . ' <' . esc_attr( UM()->options()->get( 'mail_from_addr' )) . '>' . "\r\n";
            
            if ( UM()->options()->get( 'email_html' ) == 1 ) {
                $headers .= "Content-Type: text/html\r\n";
            } else {
                $headers .= "Content-Type: text/plain\r\n";
            }
    
            wp_mail( $to, $subject, $email_content, $headers, $attachments );
    Thread Starter kooogi

    (@kooogi)

    @missveronicatv

    Okey, finnaly its work, imo. You are amazing. Ty one more time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Info about email change to old and new email adresses’ is closed to new replies.