method send documentation in bbn\Mail
function($cfg)
{
$r = false;
$headers = [];
if (!defined('BBN_IS_PROD') || !BBN_IS_PROD) {
$cfg['to'] = BBN_ADMIN_EMAIL;
$cfg['cc'] = '';
$cfg['bcc'] = '';
$this->mailer->AddAddress(BBN_ADMIN_EMAIL);
$valid = 1;
}
else {
foreach (self::$_dest_fields as $dest_field) {
if (isset($cfg[$dest_field])) {
if (!\is_array($cfg[$dest_field])) {
$cfg[$dest_field] = array_map(
function ($a) {
return trim($a);
},
explode(";", $cfg[$dest_field])
);
}
foreach ($cfg[$dest_field] as $dest) {
if (PHPMailer::validateAddress($dest)) {
switch ($dest_field) {
case "to":
$this->mailer->AddAddress($dest);
break;
case "cc":
$this->mailer->AddCC($dest);
break;
case "bcc":
$this->mailer->AddBCC($dest);
break;
}
$valid = 1;
}
else {
X::log("Adresse email invalide: ".$dest);
$valid = false;
}
}
}
}
}
if ($valid) {
if (!empty($cfg['from'])) {
$this->setFrom($cfg['from']);
}
$ar = [];
$this->mailer->Subject = $ar['title'] = $cfg['subject'] ?? ($cfg['title'] ?? '');
if (!isset($cfg['text'])) {
$cfg['text'] = '';
}
if (isset($cfg['attachments'])) {
if (\is_string($cfg['attachments'])) {
$cfg['attachments'] = [$cfg['attachments']];
}
foreach ($cfg['attachments'] as $name => $att) {
if (is_file($att)) {
// 2nd parameter is the file's name in the mail
$this->mailer->AddAttachment($att, is_int($name) ? '' : $name);
}
}
}
if (!isset($renderer)) {
$renderer = Tpl::renderer($this->template);
}
if (!empty($cfg['references'])) {
// check if each reference have chevrons around the message id and remove them
$refs = [];
$cfg['references'] = explode(' ', $cfg['references']);
foreach ($cfg['references'] as $ref) {
if (preg_match('/^<(.*)>$/', $ref, $m)) {
$mailbox = explode('@', $m[1])[0];
$hostname = explode('@', $m[1])[1];
$refs[] = imap_rfc822_write_address($mailbox, $hostname, null);
}
else {
$mailbox = explode('@', $ref)[0];
$hostname = explode('@', $ref)[1];
$refs[] = imap_rfc822_write_address($mailbox, $hostname, null);
}
}
// for each ref add '<' and '>' around the message id if not present
for ($i = 0; $i < count($refs); $i++) {
if (!preg_match('/^<(.*)>$/', $refs[$i])) {
$refs[$i] = '<' . $refs[$i] . '>';
}
}
$cfg['references'] = implode(' ', $refs);
$this->mailer->addCustomHeader('References:' . $cfg['references']);
}
if (!empty($cfg['in_reply_to'])) {
# check if the in-reply-to have chevrons around the message id and remove them
if (preg_match('/^<(.*)>$/', $cfg['in_reply_to'], $m)) {
$mailbox = explode('@', $m[1])[0];
$hostname = explode('@', $m[1])[1];
$cfg['in_reply_to'] = imap_rfc822_write_address($mailbox, $hostname, null);
} else {
$mailbox = explode('@', $cfg['in_reply_to'])[0];
$hostname = explode('@', $cfg['in_reply_to'])[1];
$cfg['in_reply_to'] = imap_rfc822_write_address($mailbox, $hostname, null);
}
// add '<' and '>' around the message id if not present
if (!preg_match('/^<(.*)>$/', $cfg['in_reply_to'])) {
$cfg['in_reply_to'] = '<' . $cfg['in_reply_to'] . '>';
}
$this->mailer->AddCustomHeader('In-Reply-To:' . mb_encode_mimeheader($cfg['in_reply_to']));
}
$ar['url'] = \defined('BBN_URL') ? BBN_URL : '';
$ar['text'] = $cfg['text'];
$ar['text'] = $renderer($ar);
self::setContent($ar['text']);
$this->mailer->msgHTML(self::$_content, $this->path, true);
try {
$r = $this->mailer->send();
}
catch (\Exception $e) {
$this->log($e->getMessage());
}
if ($r && !empty($this->imap_string)) {
$mail_string = $this->mailer->getSentMIMEMessage();
if (!\is_resource($this->imap)
&& !($this->imap instanceof \IMAP\Connection)
) {
$this->imap = \imap_open($this->imap_string, $this->imap_user, $this->imap_pass);
}
if ((!\is_resource($this->imap)
&& !($this->imap instanceof \IMAP\Connection))
|| !\imap_append($this->imap, $this->imap_string.$this->imap_sent, $mail_string, "\\Seen")
) {
$this->log(\imap_errors());
}
}
if (!$r) {
$err = \imap_last_error();
$this->log($err);
X::log($err);
}
}
$this->mailer->ClearAllRecipients();
$this->mailer->ClearAttachments();
return $r;
}
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.
© 2011-2025
BBN Solutions