Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
700 views
in Plugins by
Hi all

I wanna mention users names in the email they receive from the admin. Somthing like

Hello John

.....

 

Hello Jennfer

....

 

Hello Nik,

....

 

How can I do that?
Q2A version: 1.7

1 Answer

+1 vote
by

Open qa-include/app/mailing.php and replace the qa_mailing_send_one function with this one:

function qa_mailing_send_one($userid, $handle, $email, $emailcode)
{
    require_once QA_INCLUDE_DIR.'app/emails.php';
    require_once QA_INCLUDE_DIR.'db/users.php';

    if (!strlen(trim($emailcode))) {
        $emailcode=qa_db_user_rand_emailcode();
        qa_db_user_set($userid, 'emailcode', $emailcode);
    }

    $unsubscribeurl=qa_path_absolute('unsubscribe', array('c' => $emailcode, 'u' => $handle));

    $userprofile = qa_db_single_select(qa_db_user_profile_selectspec($userid, true));
    $userName = isset($userprofile['name']) && !empty($userprofile['name']) ? $userprofile['name'] : $handle;
    $subs = array(
        '^name' => $userName,
        '^handle' => $handle,
    );

    $emailBody = strtr(trim(qa_opt('mailing_body')), $subs);

    return qa_send_email(array(
        'fromemail' => qa_opt('mailing_from_email'),
        'fromname' => qa_opt('mailing_from_name'),
        'toemail' => $email,
        'toname' => $handle,
        'subject' => qa_opt('mailing_subject'),
        'body' => $emailBody."\n\n\n".qa_lang('users/unsubscribe').' '.$unsubscribeurl,
        'html' => false,
    ));
}

Then just use ^handle and ^name in your mass emails and they'll be replaced with the appropriate values. Note that ^name is the default name field that comes configured with Q2A and if it is deleted and recreated, it might have a different way of identifying it. Also note that as user fields are optional, which means users might not have configured a name such as Gabriel. In these cases the handle, such as pupi1985, will be used.

by
Perfect! thank you.
Can I override this qa_mailing_send_one function in my qa-theme.php or somewhere to avoid touching the core?
by
No, you can't.
by
Sure, thanks
by
+1
Hi pupi1985,

You answer worked like magic on my installation!

Thank you very much.

Tom
...