diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 0dd843813e8..a73422a8499 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -1266,8 +1266,11 @@ class FormMail extends Form
$product = new Product($this->db);
$product->fetch($line->fk_product, '', '', 1);
$product->fetch_optionals();
- foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
- $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key];
+ if (is_array($extrafieldstmp->attributes[$object->table_element]['label']) && count($extrafieldstmp->attributes[$object->table_element]['label']) > 0)
+ {
+ foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
+ $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key];
+ }
}
}
$this->substit_lines[] = $substit_line;
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index af8ae019a9c..c01aafdce1f 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -5964,11 +5964,14 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
// Create dynamic tags for __EXTRAFIELD_FIELD__
if ($object->table_element && $object->id > 0)
{
- $extrafieldstmp = new ExtraFields($db);
+ if (! is_object($extrafields)) $extrafieldstmp = new ExtraFields($db);
$extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
$object->fetch_optionals();
- foreach ($extrafieldstmp->attributes[$object->table_element]['label'] as $key => $label) {
- $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+ if (is_array($extrafieldstmp->attributes[$object->table_element]['label']) && count($extrafieldstmp->attributes[$object->table_element]['label']) > 0)
+ {
+ foreach ($extrafieldstmp->attributes[$object->table_element]['label'] as $key => $label) {
+ $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+ }
}
}