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

XF 1.1 Email Styling

Jeremy P

Well-known member
#1
Forgive me if this has been asked already (I tried searching) but what's the appropriate way to style the new emails in 1.1?

Am I correct that all the colors are inline and hardcoded? Is there no easy way to change them other then editing all the values in the template/phrase?

Thanks.
 

Jake Bunce

XenForo moderator
Staff member
#2
The HTML code for outgoing emails is in the email templates:

Admin CP -> Development -> Email Templates

The HTML uses inline styling.

This area is only accessible in debug mode. And note that while you can edit the email templates in the Admin CP, your changes will be lost the next time you upgrade. The upgrade script always imports the default email templates from this file:

install/data/email_templates.xml
 

Jeremy P

Well-known member
#3
I had figured as much. Thanks Jake.
I hope this improves before 1.1 is gold, styling the new emails is currently not feasible in the least.
 

DSF

Well-known member
#4
Jake, thanks for this information.

How can I reduce the posting content, say 30 or 50 Bytes with trailing "..." ?
 

Jake Bunce

XenForo moderator
Staff member
#6
Jake, thanks for this information.

How can I reduce the posting content, say 30 or 50 Bytes with trailing "..." ?
For which email template? You can use template syntax in the email templates so this helper might work for your purposes:

Code:
{xen:helper snippet, $MESSAGE, 50, {xen:array 'fromStart=1', 'stripQuote=1'}}
 

Morgain

Well-known member
#8
Debug mode please?

I have done what I can with Phrases - why on earth is only part of it there? These emails are dreadful and I'm getting loads of complaints after only 2 days live! Too wordy, over designed, too much STUFF before you get to the CONTENT. Not like XF usual style.
 

Morgain

Well-known member
#9
Any chance of disabling html emails?

We can edit the plain text ones but html ones are hidden behind the dire warnings of debug mode.
 

Mouth

Well-known member
#10
I am wanting to include the receivers username and email adress within MAIL_CONTAINER. I've tried both {$receiver.username} and {$user.username} with no luck. Can anyone please advise what will work?
 

Jake Bunce

XenForo moderator
Staff member
#11
I am wanting to include the receivers username and email adress within MAIL_CONTAINER. I've tried both {$receiver.username} and {$user.username} with no luck. Can anyone please advise what will work?
Untested but...

library/XenForo/Mail.php

Add the red code:

Code:
	public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
	{
		$contents = $this->prepareMailContents();
		if (!$contents)
		{
			return false;
		}

		$contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml'], $toEmail, $toName);

		$mailObj = new Zend_Mail('utf-8');
		$mailObj->setSubject($contents['subject'])
			->setBodyText($contents['bodyText'])
			->addTo($toEmail, $toName);

		if ($contents['bodyHtml'] !== '')
		{
			$mailObj->setBodyHtml($contents['bodyHtml']);
		}

		$options = XenForo_Application::get('options');
		if (!$fromName)
		{
			$fromName = ($options->emailSenderName ? $options->emailSenderName : $options->boardTitle);
		}

		if ($fromEmail)
		{
			$mailObj->setFrom($fromEmail, $fromName);
		}
		else
		{
			$mailObj->setFrom($options->defaultEmailAddress, $fromName);
		}

		if ($returnPath)
		{
			$mailObj->setReturnPath($returnPath);
		}
		else
		{
			$bounceEmailAddress = $options->bounceEmailAddress;
			if (!$bounceEmailAddress)
			{
				$bounceEmailAddress = $options->defaultEmailAddress;
			}
			$mailObj->setReturnPath($bounceEmailAddress);
		}

		foreach ($headers AS $headerName => $headerValue)
		{
			if (isset(self::$_headerMap[strtolower($headerName)])) {
				$func = self::$_headerMap[strtolower($headerName)];
				$mailObj->$func($headerValue);
			}
			else
			{
				$mailObj->addHeader($headerName, $headerValue);
			}
		}

		return $mailObj;
	}
Code:
	public function wrapMailContainer($subject, $bodyText, $bodyHtml, $toEmail, $toName = '')
	{
		$contents = $this->prepareMailContents('MAIL_CONTAINER', array(
			'subject' => $subject,
			'bodyText' => $bodyText,
			'bodyHtml' => $bodyHtml,
			'toEmail' => $toEmail,
			'toName' => $toName
		));

		if ($contents)
		{
			// remove the bodyHtml so we skip an HTML email if there's nothing
			if ($bodyHtml === '')
			{
				$contents['bodyHtml'] = '';
			}

			return $contents;
		}
		else
		{
			return array(
				'subject' => $subject,
				'bodyText' => $bodyText,
				'bodyHtml' => $bodyHtml
			);
		}
	}
That should enable you to use {$toEmail} and {$toName} in the MAIL_CONTAINER template.
 

Mouth

Well-known member
#12
Untested but...

library/XenForo/Mail.php

Add the red code:
Brilliant. Worked perfectly, thanks.

Has enabled me to put
PHP:
            <p style="font-size: 9px;">
            This email was sent to <a href="{$xenOptions.boardUrl}/account/" title="User {$toName} on Netrider">{$toName}</a> &lt;{$toEmail}&gt;, a registered member of the <b>Netrider community</b>.<br />
            <a href="{$xenOptions.boardUrl}/account/contact-details" title="Edit your messaging preferences">Edit Your Messaging Preferences</a>
            </p>
in the bottom of my MAIL_CONTAINER to ensure I meet spam regulations on all emails sent.
 

Kerby

Active member
#13
Where can I edit the "BoardTitle" inside a HTML E-Mail Text? It has to be different from ACP>Options>Preferences>Board Title setting. Here you can see the text in the red circle on screenshot:

2014-10-13_042627.png

I've tried it with debug mode and developer e-mail template modifications but it seems my TM doesn't work. I've tested it with template "conversation_reply" and "conversation_reply_messagetext". But nothing changed.

My Template Modifications settings are:
- Content as HTML
- simple replacement

find:
{$xenOptions.boardTitle}

replace:
Domain.ch Best Domains


It doesn't work. It's still "Xenforo Community" there instead of "Domain.com Best Domains".

Probably something in library/XenForo/Mail.php? Where can I edit this phrase?
 

Kerby

Active member
#15
I don't want to change globally Board Title. I only want to change the phrase in the e-mail templates. It has to be different from the board title.
 
#16
Any intention to make this easier? I want to remove messagetext from all outgoing messages; users have expressed an interest in not having their forum chats in their email.
 

Jeremy P

Well-known member
#17
Any intention to make this easier? I want to remove messagetext from all outgoing messages; users have expressed an interest in not having their forum chats in their email.
That doesn't really have anything to do with this thread, but it is already available in the core software.

Options -> Email Options:


Hard to make it much easier really.