FIX The email test sender in email setup was broken

This commit is contained in:
Laurent Destailleur 2016-09-26 14:08:14 +02:00
parent e531735444
commit fac946dbb8
3 changed files with 63 additions and 186 deletions

View File

@ -83,147 +83,17 @@ if ($action == 'update' && empty($_POST["cancel"]))
}
/*
* Add file in email form
*/
if (GETPOST('addfile') || GETPOST('addfilehtml'))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Actions to send emails
$id=0;
$actiontypecode='';
$trigger_name='';
$paramname='id';
$mode='emailfortest';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp';
dol_add_file_process($upload_dir,0,0);
if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
if ($_POST['addfile']) $action='test';
if ($_POST['addfilehtml']) $action='testhtml';
}
/*
* Remove file in email form
*/
if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml']))
{
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp';
$keytodelete=isset($_POST['removedfile'])?$_POST['removedfile']:$_POST['removedfilehtml'];
$keytodelete--;
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
$pathtodelete=$listofpaths[$keytodelete];
$filetodelete=$listofnames[$keytodelete];
$result = dol_delete_file($pathtodelete,1);
if ($result)
{
setEventMessages(array($langs->trans("FileWasRemoved"), $filetodelete), null, 'mesgs');
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->remove_attached_files($keytodelete);
}
}
if ($_POST['removedfile'] || $action='send') $action='test';
if ($_POST['removedfilehtml'] || $action='sendhtml') $action='testhtml';
}
/*
* Send mail
*/
if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GETPOST('addfilehtml') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
{
$error=0;
$email_from='';
if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' ';
if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>';
$errors_to = $_POST["errorstomail"];
$sendto = $_POST["sendto"];
$sendtocc = $_POST["sendtocc"];
$sendtoccc = $_POST["sendtoccc"];
$subject = $_POST['subject'];
$body = $_POST['message'];
$deliveryreceipt= $_POST["deliveryreceipt"];
$trackid = GETPOST('trackid');
//Check if we have to decode HTML
if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401))) {
$body=dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401);
}
// Create form object
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$attachedfiles=$formmail->get_attached_files();
$filepath = $attachedfiles['paths'];
$filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes'];
if (empty($_POST["frommail"]))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom")), null, 'errors');
$action='test';
$error++;
}
if (empty($sendto))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTo")), null, 'errors');
$action='test';
$error++;
}
if (! $error)
{
// Is the message in HTML?
$msgishtml=0; // Message is not HTML
if ($action == 'sendhtml') $msgishtml=1; // Force message to HTML
// Pratique les substitutions sur le sujet et message
$subject=make_substitutions($subject,$substitutionarrayfortest);
$body=make_substitutions($body,$substitutionarrayfortest);
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$subject,
$sendto,
$email_from,
$body,
$filepath,
$mimetype,
$filename,
$sendtocc,
$sendtoccc,
$deliveryreceipt,
$msgishtml,
$errors_to,
'',
$trackid
);
$result=$mailfile->sendfile();
if ($result)
{
setEventMessages($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($email_from,2),$mailfile->getValidAddress($sendto,2)), null, 'mesgs');
}
else
{
setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
}
$action='';
}
}
@ -747,7 +617,7 @@ else
$formmail = new FormMail($db);
$formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->trackid='test';
$formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
$formmail->withfromreadonly=0;
$formmail->withsubstit=0;
$formmail->withfrom=1;
@ -767,7 +637,7 @@ else
// Tableau des substitutions
$formmail->substit=$substitutionarrayfortest;
// Tableau des parametres complementaires du post
$formmail->param["action"]=($action == 'testhtml'?"sendhtml":"send");
$formmail->param["action"]="send";
$formmail->param["models"]="body";
$formmail->param["mailid"]=0;
$formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
@ -778,7 +648,7 @@ else
$formmail->clear_attached_files();
}
print $formmail->get_form(($action == 'testhtml'?'addfilehtml':'addfile'),($action == 'testhtml'?'removefilehtml':'removefile'));
print $formmail->get_form('addfile','removefile');
print '<br>';
}

View File

@ -21,11 +21,13 @@
* \brief Code for actions on sending mails from object page
*/
// $mysoc must be defined
// $id must be defined
// $actiontypecode must be defined
// $paramname must be defined
// $mode must be defined
// $object and $uobject may be defined.
/*
* Add file in email form
@ -107,51 +109,55 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$subject='';$actionmsg='';$actionmsg2='';
$result=$object->fetch($id);
$sendtosocid=0;
if (method_exists($object,"fetch_thirdparty") && $object->element != 'societe')
if (is_object($object))
{
$result=$object->fetch_thirdparty();
$thirdparty=$object->thirdparty;
$sendtosocid=$thirdparty->id;
$result=$object->fetch($id);
$sendtosocid=0;
if (method_exists($object,"fetch_thirdparty") && $object->element != 'societe')
{
$result=$object->fetch_thirdparty();
$thirdparty=$object->thirdparty;
$sendtosocid=$thirdparty->id;
}
else if ($object->element == 'societe')
{
$thirdparty=$object;
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
elseif($conf->dolimail->enabled)
{
$dolimail = new Dolimail($db);
$possibleaccounts=$dolimail->get_societe_by_email($_POST['sendto'],"1");
$possibleuser=$dolimail->get_from_user_by_mail($_POST['sendto'],"1"); // suche in llx_societe and socpeople
if (!$possibleaccounts && !$possibleuser)
{
setEventMessages($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']), null, 'errors');
}
elseif (count($possibleaccounts)>1)
{
$sendtosocid=$possibleaccounts[1]['id'];
$result=$object->fetch($sendtosocid);
setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs');
}
else
{
if($possibleaccounts){
$sendtosocid=$possibleaccounts[1]['id'];
$result=$object->fetch($sendtosocid);
}elseif($possibleuser){
$sendtosocid=$possibleuser[0]['id'];
$result=$uobject->fetch($sendtosocid);
$object=$uobject;
}
}
}
}
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
}
else if ($object->element == 'societe')
{
$thirdparty=$object;
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
elseif($conf->dolimail->enabled)
{
$dolimail = new Dolimail($db);
$possibleaccounts=$dolimail->get_societe_by_email($_POST['sendto'],"1");
$possibleuser=$dolimail->get_from_user_by_mail($_POST['sendto'],"1"); // suche in llx_societe and socpeople
if (!$possibleaccounts && !$possibleuser)
{
setEventMessages($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']), null, 'errors');
}
elseif (count($possibleaccounts)>1)
{
$sendtosocid=$possibleaccounts[1]['id'];
$result=$object->fetch($sendtosocid);
setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs');
}
else
{
if($possibleaccounts){
$sendtosocid=$possibleaccounts[1]['id'];
$result=$object->fetch($sendtosocid);
}elseif($possibleuser){
$sendtosocid=$possibleuser[0]['id'];
$result=$uobject->fetch($sendtosocid);
$object=$uobject;
}
}
}
}
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
else $thirdparty = $mysoc;
if ($result > 0)
{

View File

@ -269,6 +269,7 @@ class FormMail extends Form
$listofnames=array();
$listofmimes=array();
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);