• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.1 Placeholders

#1
When sending email to a user, you are told you can use {name}, {id} and {email} as placeholders. Are there any more placeholders available? And can these placeholders be used anywhere else?

I ask because I see some email phrases (like user account approved) that have placeholders like {board_title} but they don't seem to work in my outgoing emails.

Thx.
 

Jake Bunce

XenForo moderator
Staff member
#2
The tokens for the mass mailer are explicitly defined in the controller:

XenForo_ControllerAdmin_User::_sendEmail

Code:
	protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
	{
		if (!$user['email'])
		{
			return false;
		}

		$mailObj = new Zend_Mail('utf-8');
		$mailObj->setSubject($email['email_title'])
			->addTo($user['email'], $user['username'])
			->setFrom($email['from_email'], $email['from_name']);

		$options = XenForo_Application::get('options');
		$bounceEmailAddress = $options->bounceEmailAddress;
		if (!$bounceEmailAddress)
		{
			$bounceEmailAddress = $options->defaultEmailAddress;
		}
		$mailObj->setReturnPath($bounceEmailAddress);

		if ($email['email_format'] == 'html')
		{
			$replacements = array(
				'{name}' => htmlspecialchars($user['username']),
				'{email}' => htmlspecialchars($user['email']),
				'{id}' => $user['user_id']
			);
			$email['email_body'] = strtr($email['email_body'], $replacements);

			$text = trim(
				htmlspecialchars_decode(strip_tags($email['email_body']))
			);

			$mailObj->setBodyHtml($email['email_body'])
				->setBodyText($text);
		}
		else
		{
			$replacements = array(
				'{name}' => $user['username'],
				'{email}' => $user['email'],
				'{id}' => $user['user_id']
			);
			$email['email_body'] = strtr($email['email_body'], $replacements);

			$mailObj->setBodyText($email['email_body']);
		}

		try
		{
			$mailObj->send($transport);
		}
		catch (Exception $e)
		{
			return false;
		}

		return true;
	}
This code can be modified, or an addon can be created to extend this controller.

Other stock emails (e.g. activation emails) have their tokens defined in the email templates:

Admin CP -> Development -> Email Templates

For example, in the user_lost_password email template you can see the tokens defined when the phrase is called:

Code:
{xen:phrase user_lost_password_body_text,
	"username={$user.username}",
	"board_title={$boardTitle}",
	"confirm_link={xen:link 'canonical:lost-password/confirm', $user, 'c={$confirmation.confirmation_key}'}"
}
FYI, the Development tab and Email Templates are only accessible in debug mode. Add this line to your library/config.php file:

Code:
$config['debug'] = 1;