Skip to content
Snippets Groups Projects
Commit fac946db authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

FIX The email test sender in email setup was broken

parent e5317354
No related branches found
No related tags found
No related merge requests found
......@@ -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';
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp';
dol_add_file_process($upload_dir,0,0);
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';
// Actions to send emails
$id=0;
$actiontypecode='';
$trigger_name='';
$paramname='id';
$mode='emailfortest';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
$keytodelete=isset($_POST['removedfile'])?$_POST['removedfile']:$_POST['removedfilehtml'];
$keytodelete--;
if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
$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>';
}
......
......@@ -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,6 +109,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$subject='';$actionmsg='';$actionmsg2='';
if (is_object($object))
{
$result=$object->fetch($id);
$sendtosocid=0;
......@@ -152,6 +156,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
}
}
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
}
else $thirdparty = $mysoc;
if ($result > 0)
{
......
......@@ -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]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment