Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: merc123 - kesäkuu 12, 2014, 11:00:18 AP

Otsikko: Adding custom variables to activation e-mail
Kirjoitti: merc123 - kesäkuu 12, 2014, 11:00:18 AP
Hello!  I'm trying to add custom variables to the activation e-mail based on 'id_member'.  I made the changes but in the e-mail it shows {MEMBERID} instead of 231.

I modified ..\Sources\Register.php to add 'MEMBERID' => $row['id_member']

if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'resend' && ($row['is_activated'] == 0 || $row['is_activated'] == 2) && (!isset($_REQUEST['code']) || $_REQUEST['code'] == ''))
{
require_once($sourcedir . '/Subs-Post.php');

$replacements = array(
'REALNAME' => $row['real_name'],
'USERNAME' => $row['member_name'],
'MEMBERID' => $row['id_member'], 
'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $row['id_member'] . ';code=' . $row['validation_code'],
'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $row['id_member'],
'ACTIVATIONCODE' => $row['validation_code'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
);

$emaildata = loadEmailTemplate('resend_activate_message', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);


I also added it to the ..\Themese\default\languages\EmailTemplates.english.php area

'register_activate' => array(
/*
@additional_params: register_activate
REALNAME: The display name for the member receiving the email.
USERNAME: The user name for the member receiving the email.
PASSWORD: The password for the member.
MEMBERID:  Member number
ACTIVATIONLINK:  The url link to reactivate the member's account.
ACTIVATIONLINKWITHOUTCODE: The url to the page where the activation code can be entered.
ACTIVATIONCODE:  The code needed to reactivate the member's account.
FORGOTPASSWORDLINK: The url to the "forgot password" page.
@description:
*/
'subject' => 'Welcome to {FORUMNAME}',
'body' => 'Thank you for registering at {FORUMNAME}. Your username is {USERNAME} and member number is {MEMBERID}. If you forget your password, you can reset it by visiting {FORGOTPASSWORDLINK}.

Before you can login, you first need to activate your account. To do so, please follow this link:

{ACTIVATIONLINK}

Should you have any problems with activation, please visit {ACTIVATIONLINKWITHOUTCODE} use the code "{ACTIVATIONCODE}".

{REGARDS}',
),

Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: Arantor - kesäkuu 12, 2014, 11:04:51 AP
You've added it to the wrong one. You've added MEMBERID to the code that loads the resend_activate_message template but added {MEMBERID} tothe register_activate template...
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: Matthew K. - kesäkuu 12, 2014, 11:05:00 AP
Have you looked at Email Template Editor (http://custom.simplemachines.org/mods/index.php?mod=2926)?
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: merc123 - kesäkuu 12, 2014, 11:07:52 AP
Lainaus käyttäjältä: Arantor - kesäkuu 12, 2014, 11:04:51 AP
You've added it to the wrong one. You've added MEMBERID to the code that loads the resend_activate_message template but added {MEMBERID} tothe register_activate template...

Sorry, also included it in that one as well and still doesn't work.

'resend_activate_message' => array(
/*
@additional_params: resend_activate_message
REALNAME: The display name for the member receiving the email.
USERNAME:  The user name for the member receiving the email.
MEMBERID:  Member ID
ACTIVATIONLINK:  The url link to activate the member's account.
ACTIVATIONCODE:  The code needed to activate the member's account.
ACTIVATIONLINKWITHOUTCODE: The url to the page where the activation code can be entered.
FORGOTPASSWORDLINK: The url to the "forgot password" page.
@description:
*/
'subject' => 'Welcome to {FORUMNAME}',
'body' => 'Thank you for registering at {FORUMNAME}. Your username is {USERNAME} and Member number is {MEMBERID}. If you forget your password, you can reset it by visiting {FORGOTPASSWORDLINK}.

Before you can login, you must first activate your account by selecting the following link:

{ACTIVATIONLINK}

Should you have any problems with the activation, please visit {ACTIVATIONLINKWITHOUTCODE} and enter the code "{ACTIVATIONCODE}".

{REGARDS}',
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: merc123 - kesäkuu 12, 2014, 11:08:28 AP
Lainaus käyttäjältä: Labradoodle-360 - kesäkuu 12, 2014, 11:05:00 AP
Have you looked at Email Template Editor (http://custom.simplemachines.org/mods/index.php?mod=2926)?

I did but did not see where it allows you to add custom variables like what I'm looking to do.  I'll download it and check it out anyway though.
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: Matthew K. - kesäkuu 12, 2014, 11:09:39 AP
Yeah, you're right. That is definitely something I should add.
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: Arantor - kesäkuu 12, 2014, 11:09:46 AP
Of course it doesn't work... you're not looking at that email!

You need to add it where the register_activate template is set up instead...
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: merc123 - kesäkuu 12, 2014, 11:13:23 AP
Lainaus käyttäjältä: Arantor - kesäkuu 12, 2014, 11:09:46 AP
Of course it doesn't work... you're not looking at that email!

You need to add it where the register_activate template is set up instead...

Which is where?  I don't see it in the Register.php file....
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: Arantor - kesäkuu 12, 2014, 11:19:17 AP
For register_activate, Subs-Members.php around line 859.
Otsikko: Re: Adding custom variables to activation e-mail
Kirjoitti: merc123 - kesäkuu 12, 2014, 11:23:53 AP
Lainaus käyttäjältä: Arantor - kesäkuu 12, 2014, 11:19:17 AP
For register_activate, Subs-Members.php around line 859.

Just found it after opening all the php files in the sources dir and doing a find on all open files...  Was going to ask if that was the correct location.  Beat me to it.  That fixed it.  Thanks.