Forums

Custom Code for Email Body is not working

sstiller 26 Dec, 2019
Hi,
I've read the entries for creating cutomized email bodies. I created Custom Code:

<?php
$Email_body = array();
$Email_body = "<p><strong>Liebe(r) {$form->data['name']} </strong> </p>";
$Email_body = "<p></p>";
$Email_body
= "<p>vielen Dank für Ihre Nachricht. Ich werde mich schnellstmöglich mit Ihnen in Verbindung setzen.</p>";
if ( $form->subject['some_input']
) {
$Email_body
= "<p>Label: {$form->subject['some_input']}</p>";
}
if ( $form->which_calendar['some_input']
) {
$Email_body
= "<p>Label: {$form->which_calendar['some_input']}</p>";
}
if ( $form->amount['some_input']
) {
$Email_body
= "<p>Label: {$form->amount['some_input']}</p>";
}
if ( $form->size['some_input']
) {
$Email_body
= "<p>Label: {$form->size['some_input']}</p>";
}
if ( $form->picture['some_input']
) {
$Email_body
= "<p>Label: {$form->picture['some_input']}</p>";
}

$form->data['Email_template'] = implode("\n", $Email_body);
?>



Afterwards I entered {Email_template} in both "Body" sections of email tab "General" and "Auto template", but neither of These Options worked. I got error message that Body text is empty.
GreyHead 30 Dec, 2019
Hi sstiller,

Please debug your PHP. You define $Email_body as an array at the beginning, then redefine it as a series of strings each of which writes over the previous value. Please try removing the array line (and the explode at the end) then use .= to extend the string . . .
<?php
$Email_body = "<p><strong>Liebe(r) {$form->data['name']} </strong> </p>";
$Email_body .= "<p></p>";
$Email_body .= "<p>vielen Dank für Ihre Nachricht. Ich werde mich schnellstmöglich mit Ihnen in Verbindung setzen.</p>";
. . .

Bob
healyhatman 30 Dec, 2019
Also in CFv6 you use $this->data('fieldname')
This topic is locked and no more replies can be posted.