Forums

Adding some php in email body

micker 11 Jan, 2022
hello i use an old chronoform i know but i can't change
is it possible to add php code in email template to change some information on fly ?
regards
GreyHead 12 Jan, 2022
Hi micker,You can use PHP in a Custom PHP action before the Email action to build custom for data that you can
then include in the email.

Bob
micker 12 Jan, 2022
cool did you have a small tuto or documentation about this ?
for now i have a field {extensions}
and i want to create some small php check to return good result in email ?
regards
GreyHead 12 Jan, 2022
Hi micker,

What exactly do you need to do?

Bob
micker 13 Jan, 2022
hi
i have field (checkbox)
{extensions}
in email its return some arrays with value
i want to convert some value in readable value for recipeir like
$myvlaue = data in extension field;
if (!empty ($myvlaue){
if ($myvlaue == 1);
echo = 'My texte dljflmsdgjdmfgjmlfgj in body email';
} elseif ($myvlaue == 2){
echo = 'My texte 2 dljflmsdgjdmfgjmlfgj in body email';
}
etc ....
i hope its more clear
GreyHead 13 Jan, 2022
Hi micker,

Please check the CFv5 manual if you have a copy - I think the answer is there.

You can use Custom PHP something like this:
<?php
if ( !empty ($form-data['myvalue']) ) {
if ( $form-data['myvalue'] == 1 ) {
$form->data['mytext'] = 'My texte dljflmsdgjdmfgjmlfgj in body email';
. . .
?>
Then the value of mytext will be added to the form data and can be used in your email.

Bob
micker 14 Jan, 2022
ok just to be sure
1 i create a custom code block
2 drag and drop in on submit event
and my code ?
exemple
<?php
if ( !empty ($form-data['extensions']) ) {
$form->data['extensions'] = $form->data['extensions'];
}else {
$form->data['extensions']="pas d'extensions";
}
?>
my user want a value in his email if $form-data['extensions'] is empty
GreyHead 14 Jan, 2022
Hi micker,

You can simplify the code a little bit:
<?php
if ( empty ($form-data['extensions']) ) {
$form->data['extensions'] = "pas d'extensions";
}
?>
Otherwise it looks OK to me.

Bob
You need to login to be able to post a reply.