salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.52k stars 2.09k forks source link

New User Password emails do not replace variables with user information #8877

Open mikek03 opened 4 years ago

mikek03 commented 4 years ago

SuiteCRM provides a function to generate a password and email the user on new user account creation. The email that is sent is configured in Admin->Password Management under Email Templates->For system-generated password. I've used the "Edit" button to edit the predefined template and wish to include an element of personalisation, addressing the email Dear UserLastName but when insering the variable for either User Last Name (which generates $contact_user_last_name) or Employee Last Name (which generates $employee_last_name), it does not get replaced when the email is sent.

Expected Behavior

When editing the email template for "system-generated password", I place custom text including variables for $contact_user_first_name or other $contactuser..... variables. When SuiteCRM sends the new user the email, these should be replaced with the user's information, for example if I place Dear $contact_user_first_name in the template, the email should say "Dear Mike".

Actual Behavior

When the email is delivered, it simply reads "Dear $contact_user_first_name", the variable is not replaced during send.

Steps to Reproduce

  1. Go to "Admin"
  2. Go to "Password Management
  3. Ensure that the "Enable System-Generated Passwords Feature" is checked
  4. Go to the Email Templates Section
  5. Click the "Edit" button next to the system-generated passwords option
  6. Amend the email text to include "Dear $contact_user_first_name,"
  7. Save all settings
  8. Create a new user without specifying a password, ensuring to set the First Name.
  9. Check the email received, the text reads "Dear $contact_user_first_name," instead of the value specified in the user First Name field.

Context

Trying to onboard a number of users for a system hosted on behalf of a client. The users are suspicious about receiving an email that is not personalised.

Your Environment

pgorod commented 4 years ago

Workaround is to add variables in blocks like these here https://github.com/salesagility/SuiteCRM/blob/master/modules/Users/User.php#L2301

   $htmlBody = str_replace('$contact_user_first_name', $this->first_name, $htmlBody);
   $body = str_replace('$contact_user_first_name', $this->first_name, $body);

The fields are from User beans, not contact beans.

A proper fix is to make this code use full template parsing capabilities.

mikek03 commented 4 years ago

Thanks @pgorod, that works perfectly.

pgorod commented 4 years ago

Glad to hear it, but please reopen the issue, this is not fixed yet ;-)