How to access Email Document dynamic params



I have an email document created and now I want to send a mail with params set.

$mail = new \Pimcore\Mail();
$mail->setParams(["countryCode" => $countryCode, "userGivenName" => $userGivenName]);

How I can access these set parameters in the view (I am using php templating, not twig) and inside the linked controller’s action?

In the view the placeholders work but not the variables

  • This works:
  • This doesn’t
<?= $countryCode; ?>

Thanks a lot


Hi @mertaivan,

First set your param as you did already:

$mail->setParams(['myVariable' => $data]);

Then you can get that param from the request inside your controller like so:

// src/AppBundle/Controller/EmailController.php

use Symfony\Component\HttpFoundation\Request;

public function renderEmailAction(Request $request)
    $myVariable = $request->get('myVariable');

    return $this->renderTemplate('Email/my-email-template.html.php', [
        'myVariable' => $myVariable,

Now you can use it inside your email template:

<?= $myVariable; ?>

Hope this helps.


And don’t use php template engine :wink:


@aarongerig - thanks a lot, I’ll try that as soon as I get home.
@dpfaffenbauer - fair point :slight_smile:


Yes, works as expected. Thanks again.