2

In my website when a user submits the registration form and email verification is sent to them. Is there a way to change the content of the verification email that is sent after the user submits the registration form based on the gender they have selected. I'm trying to make a separate emails for male and female users.

The default email provided by Drupal says

[user:name],

Your account at [site:name] is created. You may now log in by clicking this link or copying and pasting it to your browser: [user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password.

After setting your password, you will be able to log in at [site:login-url] in the future using: username: [user:name]
password: Your password

-- [site:name] team

I want to change this. For example if the user selects "Male" for gender in the registration form so instead of [user:name], it says "Hey Boy!" and if the user selects "Female" in the registration form the email says "Hey Girl!".

Is it possible to make that change?

Thank You.

2

Okay if it's only the "Hey Girl" or "Hey Boy" you want to change,

  1. You can just simply replace the [user:name] with the gender field token which is accessible via "Available tokens" link at the bottom of the page.

so you just replace [user:name] with Hey [user:field_gender]

Note that the name of the gender field is the machine name of the field you've chosen while creating the field.

If it's not just the token and the whole content of email:

  1. Use Rules module to override the default registration email:

Event: Before saving a user account

Condition: Data Comparison (Gender is Male or Female)

Action: Send E-mail (Configure as you'd like it to be based on gender you selected at condition)

2

You've got two options:

  1. Create yourself a custom token and use that.
  2. Use the hook_mail_alter function

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail_alter/7

The token approach is the more elegant approach, but needs a bit of head-wrapping to understand the concepts. The hook_mail_alter might be an easier quick hack.

  • thanks for your response. can you please explain how I can create a custom token with this? I'm new to drupal so I'm not really sure what to do – newbie Oct 30 '14 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.