Skip to content

Commit

Permalink
Fix script to send emailings
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 2, 2017
1 parent ad095d7 commit c673d28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Expand Up @@ -48,7 +48,7 @@ class InterfaceActionsAuto extends DolibarrTriggers
* $object->actionmsg (note, long text)
* $object->actionmsg2 (label, short text)
* $object->sendtoid (id of contact or array of ids)
* $object->socid
* $object->socid (id of thirdparty)
* $object->fk_project
* $object->fk_element
* $object->elementtype
Expand Down
41 changes: 31 additions & 10 deletions scripts/emailings/mailing-send.php
Expand Up @@ -41,11 +41,12 @@
exit(-1);
}
$id=$argv[1];
if (! isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
else $login = '';

require_once ($path."../../htdocs/master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php");
require_once (DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php");


// Global variables
Expand All @@ -70,9 +71,8 @@
// for signature, we use user send as parameter
if (! empty($login)) $user->fetch('',$login);

// We get list of emailing to process
$sql = "SELECT m.rowid, m.titre, m.sujet, m.body,";
$sql.= " m.email_from, m.email_replyto, m.email_errorsto";
// We get list of emailing id to process
$sql = "SELECT m.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql.= " WHERE m.statut IN (1,2)";
if ($id != 'all')
Expand All @@ -96,12 +96,15 @@
dol_syslog("Process mailing with id ".$obj->rowid);
print "Process mailing with id ".$obj->rowid."\n";

$id = $obj->rowid;
$subject = $obj->sujet;
$message = $obj->body;
$from = $obj->email_from;
$replyto = $obj->email_replyto;
$errorsto = $obj->email_errorsto;
$emailing = new Mailing($db);
$emailing->fetch($obj->rowid);

$id = $emailing->id;
$subject = $emailing->sujet;
$message = $emailing->body;
$from = $emailing->email_from;
$replyto = $emailing->email_replyto;
$errorsto = $emailing->email_errorsto;
// Le message est-il en html
$msgishtml=-1; // Unknown by default
if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
Expand Down Expand Up @@ -232,6 +235,24 @@

dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);

// Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
// Run trigger
/*
if ($obj2->source_type == 'contact')
{
$emailing->sendtoid = $obj2->source_id;
}
if ($obj2->source_type == 'thirdparty')
{
$emailing->socid = $obj2->source_id;
}
// Call trigger
$result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user);
if ($result < 0) $error++;
// End call triggers
*/

$sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
$sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj2->rowid;
$resqlok=$db->query($sqlok);
Expand Down

0 comments on commit c673d28

Please sign in to comment.