Example #1
0
 function sendMail($admin_data, $user, $content, $partner)
 {
     global $gTables;
     global $email_enabled;
     global $email_disclaimer;
     require_once "../../library/phpmailer/class.phpmailer.php";
     require_once "../../library/phpmailer/class.smtp.php";
     //
     // Se è possibile usare la posta elettronica, si procede.
     //
     if (!$email_enabled) {
         echo "invio e-mail <b style=\"color: #ff0000;\">disabilitato... ERROR!</b><br />mail send is <b style=\"color: #ff0000;\">disabled... ERROR!</b> ";
         return;
     }
     //
     // Si procede con la costruzione del messaggio.
     //
     // definisco il server SMTP e il mittente
     $config_mailer = gaz_dbi_get_row($gTables['company_config'], 'var', 'mailer');
     $config_host = gaz_dbi_get_row($gTables['company_config'], 'var', 'smtp_server');
     $config_notif = gaz_dbi_get_row($gTables['company_config'], 'var', 'return_notification');
     $config_port = gaz_dbi_get_row($gTables['company_config'], 'var', 'smtp_port');
     $config_secure = gaz_dbi_get_row($gTables['company_config'], 'var', 'smtp_secure');
     $config_user = gaz_dbi_get_row($gTables['company_config'], 'var', 'smtp_user');
     $config_pass = gaz_dbi_get_row($gTables['company_config'], 'var', 'smtp_password');
     // se non è possibile usare ini_set allora la mail verrà trasmessa usando i
     // dati attinti su php.ini
     $body_text = gaz_dbi_get_row($gTables['body_text'], 'table_name_ref', 'body_send_doc_email');
     $mailto = $partner['e_mail'];
     //recipient
     $subject = $admin_data['ragso1'] . " " . $admin_data['ragso2'] . "-Trasmissione documenti";
     //subject
     $email_disclaimer = "" . $email_disclaimer != "" ? "<p>" . $email_disclaimer . "</p>" : "";
     // Costruisco il testo HTML dell'email
     $body_text['body_text'] .= "<h3><span style=\"color: #000000; background-color: #" . $admin_data['colore'] . ";\">Company: " . $admin_data['ragso1'] . " " . $admin_data['ragso2'] . "</span></h3>";
     $admin_data['web_url'] = trim($admin_data['web_url']);
     $body_text['body_text'] .= empty($admin_data['web_url']) ? "" : "<h4><span style=\"color: #000000;\">Web: <a href=\"" . $admin_data['web_url'] . "\">" . $admin_data['web_url'] . "</a></span></h4>";
     $body_text['body_text'] .= "<address><span style=\"color: #" . $admin_data['colore'] . ";\">User: "******" " . $user['Cognome'] . "</span><br /></address>";
     $body_text['body_text'] .= "<hr />" . $email_disclaimer;
     //
     // Inizializzo PHPMailer
     //
     $mail = new PHPMailer();
     $mail->Host = $config_host['val'];
     $mail->IsHTML();
     // Modalita' HTML
     // Imposto il server SMTP
     if (!empty($config_port['val'])) {
         $mail->Port = $config_port['val'];
         // Imposto la porta del servizio SMTP
     }
     switch ($config_mailer['val']) {
         case "smtp":
             // Invio tramite protocollo SMTP
             $mail->SMTPDebug = 2;
             // Attivo il debug
             $mail->IsSMTP();
             // Modalita' SMTP
             if (!empty($config_secure['val'])) {
                 $mail->SMTPSecure = $config_secure['val'];
                 // Invio tramite protocollo criptato
             }
             $mail->SMTPAuth = !empty($config_user['val']) && $config_mailer['val'] == 'smtp' ? TRUE : FALSE;
             if ($mail->SMTPAuth) {
                 $mail->Username = $config_user['val'];
                 // Imposto username per autenticazione SMTP
                 $mail->Password = $config_pass['val'];
                 // Imposto password per autenticazione SMTP
             }
             break;
         case "mail":
         default:
             break;
     }
     // Imposto eventuale richiesta di notifica
     if ($config_notif['val'] == 'yes') {
         $mail->AddCustomHeader($mail->HeaderLine("Disposition-notification-to", $admin_data['e_mail']));
     }
     // Imposto email del mittente
     $mail->SetFrom($admin_data['e_mail'], $admin_data['ragso1'] . " " . $admin_data['ragso2']);
     // Imposto email del destinatario
     $mail->AddAddress($mailto);
     // Aggiungo l'email del mittente tra i destinatari in cc
     $mail->AddCC($admin_data['e_mail'], $admin_data['ragso1'] . " " . $admin_data['ragso2']);
     // Imposto l'oggetto dell'email
     $mail->Subject = $subject;
     // Imposto il testo HTML dell'email
     $mail->MsgHTML($body_text['body_text']);
     // Aggiungo la fattura in allegato
     $mail->AddStringAttachment($content->string, $content->name, $content->encoding, $content->mimeType);
     // Invio...
     if ($mail->Send()) {
         echo "invio e-mail riuscito... <strong>OK</strong><br />mail send has been successful... <strong>OK</strong>";
         // or use booleans here
     } else {
         echo "<br />invio e-mail <strong style=\"color: #ff0000;\">NON riuscito... ERROR!</strong><br />mail send has<strong style=\"color: #ff0000;\"> NOT been successful... ERROR!</strong> ";
         echo "<br />mailer error: " . $mail->ErrorInfo;
     }
 }
Example #2
0
/**
 * Master email function, use for all emails (public calendar & admin console) except newsletter mailings, wrapper for PHPMailer.
 * @since 2.0.0
 * @version 2.2.0
 * @param string $toName name of email recipient
 * @param string|array $toAddress email address of recipient OR array of recipients array($name => $address)
 * @param string $subj subject line of the email
 * @param string $msg message body/contents of the email
 * @param string $fromName name of email sender
 * @param string $fromAddress email Address of email sender
 * @param array $attach Files to attach to email. (Data String, Filename, MIME Type)
 * @param boolean $debug [optional] true = output PHPMailer() SMTP debug info, false = no output (Default:false)
 * @return void
 */
function reMail($toName, $toAddress, $subj, $msg, $fromName = '', $fromAddress = '', $attach = NULL, $debug = false)
{
    global $hc_cfg, $hc_lang_core, $hc_lang_config;
    if (emailStatus() != 1) {
        return -1;
    }
    emailStop();
    if ($hc_cfg[78] == '' || $hc_cfg[79] == '') {
        exit($hc_lang_core['NoEmail']);
    }
    include_once HCPATH . HCINC . '/phpmailer/class.phpmailer.php';
    $fromName = $fromName == '' ? $hc_cfg[79] : $fromName;
    $fromAddress = $fromAddress == '' ? $hc_cfg[78] : $fromAddress;
    $mail = new PHPMailer();
    $host = gethostbynamel('');
    $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-Version', $hc_cfg[49]));
    $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-ID', md5($hc_cfg[19])));
    $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-IP', $host[0]));
    /*	End Edit Restriction
     */
    $mail->CreateHeader();
    $mail->IsHTML(true);
    $mail->CharSet = defined('CONVERT_CHRSET') && function_exists('mb_convert_encoding') ? CONVERT_CHRSET : $hc_lang_config['CharSet'];
    if ($attach != NULL) {
        $mail->AddStringAttachment("{$attach['0']}", "{$attach['1']}", "base64", "{$attach['2']}");
    }
    if (is_array($toAddress)) {
        $mail->SingleToArray = $toAddress;
        foreach ($toAddress as $name => $address) {
            $mail->AddAddress($address, $name);
        }
    } else {
        $mail->AddAddress($toAddress, $toName);
    }
    if ($hc_cfg[71] == 1) {
        $mail->IsSMTP();
        $mail->SMTPKeepAlive = false;
        $mail->SMTPDebug = $debug;
        $mail->Host = $hc_cfg[72];
        $mail->Port = $hc_cfg[73];
        if ($hc_cfg[77] == 1) {
            $mail->SMTPAuth = true;
            $mail->Username = $hc_cfg[75];
            $mail->Password = base64_decode($hc_cfg[76]);
        }
        if ($hc_cfg[74] == 1) {
            $mail->SMTPSecure = "tls";
        } elseif ($hc_cfg[74] == 2) {
            $mail->SMTPSecure = "ssl";
        }
    } else {
        $mail->IsMail();
    }
    $mail->Sender = $hc_cfg[78];
    $mail->From = $fromAddress;
    $mail->FromName = cOut($fromName);
    $mail->AddReplyTo($fromAddress, $fromName);
    $mail->Subject = $subj;
    $mail->Body = $msg;
    $mail->AltBody = strip_tags(str_replace("<br />", "\n", $msg));
    try {
        $mail->Send();
    } catch (phpmailerException $e) {
        exit($e);
    } catch (Exception $e) {
        exit($e);
    }
    if ($hc_cfg[71] == 1) {
        $mail->SmtpClose();
    }
    emailGo();
}
Example #3
0
     $newsletter = buildPersonal($newsletter, $start, $end, 0, '', '', '', '', '');
     $newsletter = str_replace('<a', '<a rel="nofollow"', $newsletter);
     doQuery("UPDATE " . HC_TblPrefix . "newsletters SET ArchiveContents = '" . cIn($newsletter, 0) . "' WHERE PkID = '" . $nID . "'");
     echo '<div class="progBar" style="background-image: url(../img/progress/go.png);background-position:-500px 0px;">&nbsp;&nbsp;' . $hc_lang_news['Status0'] . '</div>';
 } else {
     if ($prog < 100) {
         if (mysql_result($result, 0, 2) == 2) {
             echo '<div class="progBar" style="background-image: url(../img/progress/pause.png);background-position:' . $position . 'px 0px;">&nbsp;&nbsp;' . $hc_lang_news['Status2'] . ' (' . abs(number_format($prog, 0)) . '%)</div>';
         } else {
             $newsletterDefault = buildUniversal($nID);
             $resultS = doQuery("SELECT s.PkID, s.FirstName, s.LastName, s.Email, s.Zip, s.`Format`,\r\n\t\t\t\t\t\t\t\t(SELECT GROUP_CONCAT(c.PkID)\r\n\t\t\t\t\t\t\t\t\tFROM " . HC_TblPrefix . "subscriberscategories sc\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN " . HC_TblPrefix . "categories c ON (c.PkID = sc.CategoryID)\r\n\t\t\t\t\t\t\t\t\tWHERE c.IsActive = 1 AND sc.UserID = s.PkID\r\n\t\t\t\t\t\t\t\t) as Categories\r\n\t\t\t\t\t\t\t\tFROM " . HC_TblPrefix . "newssubscribers ns\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN " . HC_TblPrefix . "subscribers s ON (s.PkID = ns.SubscriberID)\r\n\t\t\t\t\t\t\t\tWHERE ns.NewsletterID = '" . $nID . "'\r\n\t\t\t\t\t\t\t\tLIMIT " . $hc_cfg[81]);
             if (hasRows($resultS)) {
                 include_once HCPATH . HCINC . '/phpmailer/class.phpmailer.php';
                 $mail = new PHPMailer();
                 $host = gethostbynamel('');
                 $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-Version', $hc_cfg[49]));
                 $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-ID', md5($hc_cfg[19])));
                 $mail->AddCustomHeader($mail->HeaderLine('X-Helios_Calendar-IP', $host[0]));
                 $mail->CreateHeader();
                 $mail->IsHTML(true);
                 if ($hc_cfg[71] == 1) {
                     $mail->IsSMTP();
                     $mail->SMTPKeepAlive = true;
                     $mail->SMTPDebug = false;
                     $mail->Host = $hc_cfg[72];
                     $mail->Port = $hc_cfg[73];
                     if ($hc_cfg[77] == 1) {
                         $mail->SMTPAuth = true;
                         $mail->Username = $hc_cfg[75];
                         $mail->Password = base64_decode($hc_cfg[76]);
                     }
Example #4
0
function phorum_smtp_send_messages($data)
{
    $PHORUM = $GLOBALS["PHORUM"];
    $addresses = $data['addresses'];
    $subject = $data['subject'];
    $message = $data['body'];
    $num_addresses = count($addresses);
    $settings = $PHORUM['smtp_mail'];
    $settings['auth'] = empty($settings['auth']) ? false : true;
    if ($num_addresses > 0) {
        try {
            require "./mods/smtp_mail/phpmailer/class.phpmailer.php";
            $mail = new PHPMailer();
            $mail->PluginDir = "./mods/smtp_mail/phpmailer/";
            $mail->CharSet = $PHORUM["DATA"]["CHARSET"];
            $mail->Encoding = $PHORUM["DATA"]["MAILENCODING"];
            $mail->Mailer = "smtp";
            $mail->IsHTML(false);
            $mail->From = $PHORUM['system_email_from_address'];
            $mail->Sender = $PHORUM['system_email_from_address'];
            $mail->FromName = $PHORUM['system_email_from_name'];
            if (!isset($settings['host']) || empty($settings['host'])) {
                $settings['host'] = 'localhost';
            }
            if (!isset($settings['port']) || empty($settings['port'])) {
                $settings['port'] = '25';
            }
            $mail->Host = $settings['host'];
            $mail->Port = $settings['port'];
            // set the connection type
            if ($settings['conn'] == 'ssl') {
                $mail->SMTPSecure = "ssl";
            } elseif ($settings['conn'] == 'tls') {
                $mail->SMTPSecure = "tls";
            }
            // smtp-authentication
            if ($settings['auth'] && !empty($settings['username'])) {
                $mail->SMTPAuth = true;
                $mail->Username = $settings['username'];
                $mail->Password = $settings['password'];
            }
            $mail->Body = $message;
            $mail->Subject = $subject;
            // add the newly created message-id
            $mail->HeaderLine("Message-ID", $data['messageid']);
            // add attachments if provided
            if (isset($data['attachments']) && count($data['attachments'])) {
                /*
                 * Expected input is an array of
                 * 
                 * array(
                 * 'filename'=>'name of the file including extension',
                 * 'filedata'=>'plain (not encoded) content of the file',
                 * 'mimetype'=>'mime type of the file', (optional)
                 * )
                 * 
                 */
                foreach ($data['attachments'] as $att_id => $attachment) {
                    $att_type = !empty($attachment['mimetype']) ? $attachment['mimetype'] : 'application/octet-stream';
                    $mail->AddStringAttachment($attachment['filedata'], $attachment['filename'], 'base64', $att_type);
                    // try to unset it in the original array to save memory
                    unset($data['attachments'][$att_id]);
                }
            }
            if (!empty($settings['bcc']) && $num_addresses > 3) {
                $bcc = 1;
                $mail->AddAddress("undisclosed-recipients:;");
            } else {
                $bcc = 0;
                // lets keep the connection alive - it could be multiple mails
                $mail->SMTPKeepAlive = true;
            }
            foreach ($addresses as $address) {
                if ($bcc) {
                    $mail->addBCC($address);
                } else {
                    $mail->AddAddress($address);
                    if (!$mail->Send()) {
                        echo "There was an error sending the message.\n";
                        echo "Error returned was " . $mail->ErrorInfo;
                    }
                    // Clear all addresses  for next loop
                    $mail->ClearAddresses();
                }
            }
            // bcc needs just one send call
            if ($bcc) {
                if (!$mail->Send()) {
                    echo "There was an error sending the bcc message.\n";
                    echo "Error returned was " . $mail->ErrorInfo;
                }
            }
            // we have to close the connection with pipelining
            // which is only used in non-bcc mode
            if (!$bcc) {
                $mail->SmtpClose();
            }
        } catch (Exception $e) {
            echo "There was a problem communicating with SMTP: " . $e->getMessage();
            exit;
        }
    }
    unset($message);
    unset($mail);
    // make sure that the internal mail-facility doesn't kick in
    return 0;
}