From 5ec01b3175625c9623c6b00353e738ff44c1cbea Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 15 Feb 2017 11:41:09 +0100 Subject: [PATCH 1/2] NEW : Can send email to multiple destinaries from mailform --- htdocs/core/actions_sendmails.inc.php | 86 ++++++++++++++++------- htdocs/core/class/html.formmail.class.php | 4 +- htdocs/societe/class/societe.class.php | 2 +- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 28799231fdd..aad57a90894 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -160,24 +160,33 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if ($result > 0) { + $receiver=$_POST['receiver']; + $sendto_array=array(); + if (trim($_POST['sendto'])) { // Recipient is provided into free text $sendto = trim($_POST['sendto']); - $sendtoid = 0; + $sendtoid = array(); } - elseif ($_POST['receiver'] != '-1') + elseif (count($receiver)>0) { - // Recipient was provided from combo list - if ($_POST['receiver'] == 'thirdparty') // Id of third party - { - $sendto = $thirdparty->name.' <'.$thirdparty->email.'>'; - $sendtoid = 0; + foreach($receiver as $key=>$val) { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Id of third party + { + $sendto_array[] = $thirdparty->name.' <'.$thirdparty->email.'>'; + $sendtoid = array(); + } + else // Id du contact + { + $sendto_array[] = $thirdparty->contact_get_property((int) $val,'email'); + $sendtoid[] = $val; + } } - else // Id du contact - { - $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email'); - $sendtoid = $_POST['receiver']; + + if (count($sendto_array)>0) { + $sendto=implode(',',$sendto_array); } } if (trim($_POST['sendtocc'])) @@ -339,22 +348,45 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // Initialisation of datas if (is_object($object)) { - $object->socid = $sendtosocid; // To link to a company - $object->sendtoid = $sendtoid; // To link to a contact/address - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; // Long text - $object->actionmsg2 = $actionmsg2; // Short text - $object->trackid = $trackid; - $object->fk_element = $object->id; - $object->elementtype = $object->element; - - // Call of triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf); - if ($result < 0) { - $error++; $errors=$interface->errors; - } + //multiple contact sends + if (count($sendtoid) >0) { + foreach($sendtoid as $val_id) { + $object->socid = $sendtosocid; // To link to a company + $object->sendtoid = $val_id; // To link to a contact/address + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; // Long text + $object->actionmsg2 = $actionmsg2; // Short text + $object->trackid = $trackid; + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Call of triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $errors=$interface->errors; + } + } + } else { + //Thirdparty send + $object->socid = $sendtosocid; // To link to a company + $object->sendtoid = 0; // To link to a contact/address + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; // Long text + $object->actionmsg2 = $actionmsg2; // Short text + $object->trackid = $trackid; + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Call of triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $errors=$interface->errors; + } + } // End call of triggers } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index a85b8157732..f344e3ca9b1 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -521,7 +521,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, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails); + $out.= $form->multiselectarray("receiver", $this->withto, GETPOST("receiver"), null, null, null,null, "90%"); } if (isset($this->withtosocid) && $this->withtosocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method. { @@ -533,7 +533,7 @@ class FormMail extends Form $liste[$key]=$value; } if ($this->withtofree) $out.= " ".$langs->trans("or")." "; - $out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails); + $out.= $form->multiselectarray("receiver", $liste, GETPOST("receiver")); } } $out.= "\n"; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 86fb2d88a1e..656a886c13c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2026,7 +2026,7 @@ class Societe extends CommonObject if ($this->email && $addthirdparty) { if (empty($this->name)) $this->name=$this->nom; - $contact_emails['thirdparty']=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">"; + $contact_emails['thirdparty']=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." (".$this->email.")"; } return $contact_emails; } From a98e5b7290232e412975845f836650762e308289 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 15 Feb 2017 11:46:36 +0100 Subject: [PATCH 2/2] fix syntax --- htdocs/core/class/html.formmail.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index f344e3ca9b1..69cda9eb3af 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -533,7 +533,7 @@ class FormMail extends Form $liste[$key]=$value; } if ($this->withtofree) $out.= " ".$langs->trans("or")." "; - $out.= $form->multiselectarray("receiver", $liste, GETPOST("receiver")); + $out.= $form->multiselectarray("receiver", $liste, GETPOST("receiver"), null, null, null,null, "90%"); } } $out.= "\n";