method process documentation in bbn\Appui\Mailing

Sends the emails to be sent in the limit provided.

function(int $limit = 10) { if ($this->check()) { $sent = 0; $successes = 0; $mailings = []; foreach ($this->db->rselectAll( [ 'table' => 'bbn_emails', 'fields' => ['bbn_emails.id', 'email', 'id_mailing', 'subject', 'text', 'cfg', 'status', 'delivery', 'read', 'priority'], 'join' => [[ 'table' => 'bbn_emailings', 'type' => 'left', 'on' => [ 'conditions' => [ [ 'field' => 'id_mailing', 'exp' => 'bbn_emailings.id' ] ] ] ]], 'where' => [ 'conditions' => [ 'status' => 'ready', [ 'logic' => 'OR', 'conditions' => [ [ 'field' => 'delivery', 'operator' => 'isnull' ], [ 'field' => 'delivery', 'operator' => '<', 'exp' => 'NOW()' ] ] ], [ 'logic' => 'OR', 'conditions' => [ [ 'field' => 'bbn_emailings.state', 'operator' => 'isnull' ], [ 'field' => 'bbn_emailings.state', 'value' => 'ready' ], [ 'field' => 'bbn_emailings.state', 'value' => 'sending' ] ] ] ] ], 'order' => ['priority'], 'limit' => $limit ] ) as $r) { $sent++; $ok = false; $att = []; if (!empty($r['id_mailing'])) { if (!isset($mailings[$r['id_mailing']])) { $mailings[$r['id_mailing']] = $this->getMailing($r['id_mailing']); } $mailing = &$mailings[$r['id_mailing']]; if ($mailing['state'] === 'ready') { $this->changeState($r['id_mailing'], 'sending'); $mailing['state'] = 'sending'; } $text = $mailing['content']; $subject = $mailing['title']; $sender = $mailing['sender']; if (!empty($mailing['medias'])) { foreach ($mailing['medias'] as $a){ if (!empty($a['file']) && file_exists($a['file'])) { $att[] = $a['file']; } } } } else{ $text = $r['text']; $subject = $r['subject']; $sender = null; if ($r['cfg']) { $r['cfg'] = json_decode($r['cfg'], true); if (!empty($r['cfg']['attachments'])) { foreach ($r['cfg']['attachments'] as $a){ $f = \bbn\X::indexOf($a, '/') === 0 ? $a : \bbn\Mvc::getContentPath().$a; if (file_exists($f)) { $att[] = $f; } } } } } if ($subject && $text && \bbn\Str::isEmail($r['email'])) { $params = [ 'to' => $r['email'], 'subject' => $subject, 'text' => $text ]; if (count($att)) { $params['attachments'] = $att; } if ($ok = $this->send($params, $sender)) { $successes++; } } $this->db->update( 'bbn_emails', [ 'status' => $ok ? 'success' : 'failure', 'delivery' => date('Y-m-d H:i:s') ], ['id' => $r['id']] ); } foreach ($mailings as $id => $m) { if (($m['state'] === 'sending') && !$this->db->count( 'bbn_emails', [ 'id_mailing' => $id, 'status'=> 'ready' ] ) ) { $this->changeState($id, 'sent'); } } return $successes; } $this->setError(X::_("No mailer defined")); return null; }

Sends the emails to be sent in the limit provided. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.