diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index c9e57eeaa4d..8abe3f271f7 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -4857,12 +4857,13 @@ class Form
* @param int $disabled Html select box is disabled
* @param string $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' or 'POS' = Do not sort, we keep original order
* @param string $morecss Add more class to css styles
- * @param int $addjscombo Add js combo
+ * @param int $addjscombo Add js combo
* @param string $moreparamonempty Add more param on the empty option line. Not used if show_empty not set.
- * @return string HTML select string.
+ * @param int $disablebademail Check if an email is found into value and if not disable and colorize entry.
+ * @return string HTML select string.
* @see multiselectarray
*/
- static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='')
+ static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='',$disablebademail=0)
{
global $conf, $langs;
@@ -4907,7 +4908,10 @@ class Form
// Translate
if ($translate)
{
- foreach($array as $key => $value) $array[$key]=$langs->trans($value);
+ foreach($array as $key => $value)
+ {
+ $array[$key]=$langs->trans($value);
+ }
}
// Sort
@@ -4916,8 +4920,19 @@ class Form
foreach($array as $key => $value)
{
+ $disabled=''; $style='';
+ if (! empty($disablebademail))
+ {
+ if (! preg_match('/<.+@.+>/', $value))
+ {
+ //$value=preg_replace('/'.preg_quote($a,'/').'/', $b, $value);
+ $disabled=' disabled';
+ $style=' class="warning"';
+ }
+ }
$out.='\n";
}
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 6d88e735770..013b34699d7 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -264,6 +264,8 @@ class FormMail extends Form
{
$out='';
+ $disablebademails=1;
+
// Define list of attached files
$listofpaths=array();
$listofnames=array();
@@ -392,7 +394,15 @@ class FormMail extends Form
}
} else {
$liste = array();
- $liste['user'] = $user->getFullName($langs) .' <'.$user->email.'>';
+ if (empty($user->email))
+ {
+ $langs->load('errors');
+ $liste['user'] = $user->getFullName($langs) . ' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>';
+ }
+ else
+ {
+ $liste['user'] = $user->getFullName($langs) .' <'.$user->email.'>';
+ }
$liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
// Add also email aliases if there is one
$listaliases=array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
@@ -413,7 +423,7 @@ class FormMail extends Form
}
}
}
- $out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0);
+ $out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
$out.= "\n";
@@ -510,7 +520,7 @@ class FormMail extends Form
if (! empty($this->withto) && is_array($this->withto))
{
if (! empty($this->withtofree)) $out.= " ".$langs->trans("or")." ";
- $out.= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1);
+ $out.= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
if (isset($this->withtosocid) && $this->withtosocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
{
@@ -522,7 +532,7 @@ class FormMail extends Form
$liste[$key]=$value;
}
if ($this->withtofree) $out.= " ".$langs->trans("or")." ";
- $out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
+ $out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
}
$out.= "\n";
@@ -544,7 +554,7 @@ class FormMail extends Form
if (! empty($this->withtocc) && is_array($this->withtocc))
{
$out.= " ".$langs->trans("or")." ";
- $out.= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1);
+ $out.= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
}
$out.= "\n";