By hhanna on
The variables available to the system emails are very limited (!username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url)
I've been asked to add a variable containing the user's first and last name to the welcome email.
Using the profile module, I customized the registration form to capture the first and last name.
How can I modify the variables available to the welcome email so as to include the user's first and last name? Where would I define and set the variables?
Any help is greatly appreciated.
Comments
Wondering the same thing????
Anyone Know??
Is it possible
i am also having the same problem.Did u find the solution for it
The solution
I ended up writing my own module to modify the registration email from drupal. This module makes the following replacements tokens available: !first, !middle, !last, !fullname, !username, !site. So, you must add these tokens to your email subject/body using the adminstration interface: administer > user management > user settings > user email settings.
Basically, when you send an email, you're usually using a form, so right there it opens the door to modifying the form contents:
1. I use hook_form_alter() to inject the new script in the form processing flow.
2. I use hook_mail_alter() to get the registrant name and make the replacements based on which form is being processed.
3. Using the site administration interface, I add the tokens to be replaced in the message fields.
Caveats:
1. You have to be using the profile module to have added the first, middle, last fields to the registration form. This script queries the profile tables to get the first, last, middle values.
2. Since my site's registrants have to be approved by an admin, I need to send emails to the admins to let them know someone has asks to register. So, this module adds an administration form field where you can enter the admin emails that need to be notified someone is requesting membership.
I haven't fully documented the code and I'm pretty sure I never will. Below is the code for both the modifyMail.info file and modifyMail.module file.
modifyMail.info is as follows:
modifyMail.module is as follows:
When the token-module
When the token-module accepts profile content, you could use the Mail Editor module: http://drupal.org/project/mail_edit which gives you the ability to edit every e-mail template with added token-support.
not sure how it will affect
not sure how it will affect the registration email but the http://drupal.org/project/realname module may be worth a look.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
sample code snippet
hey,
you can try the following link for the code snippet that can help you out, short and sweet, does exactly what we need..
http://www.innoraft.com/blog/use-profile-fields-tokens-user-emails-drupal
Mukesh Agarwal
www.innoraft.com
token_registration_mails module
See the token_registration_mails module for genuine Token support. This includes e.g. first/last name from profiles.