diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index 7d4e382723c..71b1487ab44 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -71,6 +71,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
{
dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT"),'chaine',0,'',$conf->entity);
// Send mode parameters
dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',$conf->entity);
@@ -271,6 +272,12 @@ if ($action == 'edit')
print '';
print '';
+
+ //Add user to select destinaries list
+ print '
| '.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").' | ';
+ print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT',$conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT,1);
+ print ' |
';
+
// Separator
print '| |
';
@@ -541,6 +548,9 @@ else
if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
print '';
+ //Add user to select destinaries list
+ print '| '.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").' | '.yn($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT).' |
';
+
// Separator
print '| |
';
diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php
index 9f5224a71d3..3498bbc132c 100644
--- a/htdocs/core/actions_sendmails.inc.php
+++ b/htdocs/core/actions_sendmails.inc.php
@@ -170,6 +170,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$sendtocc='';
$sendtobcc='';
$sendtoid = array();
+ if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
+ $sendtouserid=array();
+ }
// Define $sendto
$receiver=$_POST['receiver'];
@@ -192,14 +195,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
if ($val == 'thirdparty') // Id of third party
{
$tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
- }
- elseif ($val) // Id du contact
+ } elseif ($val) // Id du contact
{
$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
$sendtoid[] = $val;
}
}
}
+ if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
+ $receiveruser=$_POST['receiveruser'];
+ if (is_array($receiveruser) && count($receiveruser)>0)
+ {
+ $fuserdest = new User($db);
+ foreach($receiveruser as $key=>$val)
+ {
+ $tmparray[] = $fuserdest->user_get_property($key,'email');
+ $sendtouserid[] = $key;
+ }
+ }
+ }
$sendto=implode(',',$tmparray);
// Define $sendtocc
@@ -230,6 +244,19 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
}
}
}
+ if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
+ $receiveruser=$_POST['receiveccruser'];
+
+ if (is_array($receiveruser) && count($receiveruser)>0)
+ {
+ $fuserdest = new User($db);
+ foreach($receiveruser as $key=>$val)
+ {
+ $tmparray[] = $fuserdest->user_get_property($key,'email');
+ $sendtouserid[] = $key;
+ }
+ }
+ }
$sendtocc=implode(',',$tmparray);
if (dol_strlen($sendto))
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 5ff93994e73..b2f64f4298d 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -81,6 +81,9 @@ class FormMail extends Form
var $substit_lines=array();
var $param=array();
+ public $withtouser=array();
+ public $withtoccuser=array();
+
var $error;
public $lines_model;
@@ -332,7 +335,7 @@ class FormMail extends Form
$out.= "\n".''."\n";
if ($this->withform == 1)
{
- $out.= '