Is it possible to allow PHP in the Expresso Store email templates? I can't see settings to do so in the admin.

The reason I need to do so is as follows.

We are going to use the Status message field to pass a parcel tracking code to the email template so the customer can track their parcel. However, if the parcel is going to the USA then we need to allow 2 tracking codes (one for the UK, then the next for the US leg of the journey).

We were going to enter both codes in the message box separated by the | (pipe) symbol, but we obviously need some way to split that apart on the template.

If anyone can suggest a better way to add two tracking codes then I'd be glad to hear it!

Thanks in advance for your advice.


  • Thanks Anna, I have tried PHP - it just spits out the code verbatum. – Tomtids Feb 18 '13 at 16:51
  • To be precise I used this code in the template ":<?php $i=2; echo $i; ?>:", and that is exactly how it appeared in the received email. – Tomtids Feb 18 '13 at 16:58

I couldn't work out how to make PHP work, but I did realise that I could use almost EE tag in the email - so I wrote a new plugin that would expose the PHP explode function to the template via a tag.

I've submitted the plugin to Devot-ee http://devot-ee.com/add-ons/string-explode-tag but the code is below as well!

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 * String Explode Tag Class
 * @package     ExpressionEngine
 * @category    Plugin
 * @author      Tom Burr
 * @copyright   Copyright (c) 2013, Turned Out Nice Again
 * @link        http://niceagain.co.uk

$plugin_info = array(
    'pi_name'           => 'Explode String Exp',
    'pi_version'        => '1.0',
'pi_author'         => 'Tom Burr',
'pi_author_url'     => 'http://niceagain.co.uk/',
'pi_description'    => 'Tag for PHP explode() function.',
'pi_usage'          =>  StrExplode::usage()

class StrExplode

public $return_data = "";

// --------------------------------------------------------------------

 * Str Explode creator
 * This function explodes a string into an array and returns the designated index value
 * @access  public
 * @return  string
public function __construct()
    $this->EE =& get_instance();
    $this->return_data = "";

    $string = $this->EE->TMPL->fetch_param('string', '');
    $delimiter = $this->EE->TMPL->fetch_param('delimiter', '');
    $index  = intval($this->EE->TMPL->fetch_param('index', "0"));

    //Output transformed string
    $tempArray = explode($delimiter, $string);
    if(count($tempArray) - 1 < $index)
        $this->return_data = $tempArray[count($tempArray) - 1];
        $this->return_data = $tempArray[$index];

// --------------------------------------------------------------------

 * Usage
 * This function describes how the plugin is used.
 * @access  public
 * @return  string
public static function usage()

    Sometimes you need to use PHP functions but don't want to
    enable PHP in the template. This plugin allows you to use 
    the PHP explode function in an EE tag passing the
    delimiter, array index, and string to search as parameters. 

    With this plugin you can pass EE variables to the tag 
    which will process them and return the index value from the array.

    This example returns the string 'value2';

    {exp:strexplode delimiter="|" index="1" string="value1|value2" }


    Thanks to Christopher Reding's ( http://christopherreding.com/ ) "Tag for PHP str_replace() function" for the inspiration for this plugin.

    $buffer = ob_get_contents();


    return $buffer;

/* End of file pi.strexplode.php */ 
/* Location: ./system/expressionengine/third_party/strexplode/pi.strexplode.php */ 

This can then be called in the email (or any) template using the tag:

{exp:strexplode index="0" string="{order_status_message}" delimiter="|"}
| improve this answer | |

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.