Forums

Passing PHP variables to email template

James181 25 Sep, 2010
Hi,

I am looking for a way to pass PHP variables from my form to the email template or even if this is possible?

What I am looking to do is put a conditional statement within the email template to send different emails dependent on the PHP values passed though. It seems I can pass field {values} through fine but not PHP.

I have carried out a search and tried various things mentioned such as getstring() etc, but none seem to work. Any ideas?

thanks in advance.
GreyHead 25 Sep, 2010
Hi James181,

If you turn off the Rich Editor in the Email Setup | Properties box then you can add PHP directly to the Email template.

Bob
James181 25 Sep, 2010
Hi Greyhead,

Thanks for your quick reply. I already have the editor turned off so I can display PHP, however it is the PHP values sent from the form that do not seem to pass though.

For example; if I set a variable '$test' in the form code box, I am not able to echo this in the emails. I know that PHP is switched on in the email because I can echo basic text statements.

I am thinking this has something to do with sessions?

thanks
GreyHead 25 Sep, 2010
Hi James181,

You could declare the variables as global and pass them that way but it's generally easier to use the PHP $_POST array where the form results are stored. I tend to use the Joomla! code to access them

$var = JRequest::getVar('var', '', 'post');

YOu can also use getString(), getInt(), . . . to add more validation; and you can set a default value in the second parameter.

To 'set' rather than 'get' use
JRequest::setVar('var', $var);


Bob
James181 26 Sep, 2010
Hi Bob,

$var = JRequest::getVar('var', '', 'post'); in the email template did the trick!

Thanks for your help, I have another PHP related query but I will create another post for that.
This topic is locked and no more replies can be posted.