Exemple #1
0
function mailpmb($to_nom = "", $to_mail, $obj = "", $corps = "", $from_name = "", $from_mail, $headers, $copie_CC = "", $copie_BCC = "", $faire_nl2br = 0, $pieces_jointes = array(), $reply_name = "", $reply_mail = "")
{
    global $opac_mail_methode, $opac_mail_html_format, $opac_mail_adresse_from;
    global $charset;
    if (!is_array($pieces_jointes)) {
        $pieces_jointes = array();
    }
    $param = explode(",", $opac_mail_methode);
    if (!$param) {
        $param = array();
    }
    $mail = new PHPmailer();
    $mail->CharSet = $charset;
    if ($copie_CC) {
        $destinataires_CC = explode(";", $copie_CC);
    } else {
        $destinataires_CC = array();
    }
    if ($copie_BCC) {
        $destinataires_BCC = explode(";", $copie_BCC);
    } else {
        $destinataires_BCC = array();
    }
    $destinataires = explode(";", $to_mail);
    switch ($param[0]) {
        case 'smtp':
            // $pmb_mail_methode = méthode, hote:port, auth, name, pass
            $mail->IsSMTP();
            $mail->Host = $param[1];
            if ($param[2]) {
                $mail->SMTPAuth = true;
                $mail->Username = $param[3];
                $mail->Password = $param[4];
                if ($param[5]) {
                    $mail->SMTPSecure = $param[5];
                }
                // pour traitement connexion SSL
            }
            break;
        default:
        case 'php':
            $mail->IsMail();
            $to_nom = "";
            break;
    }
    if ($opac_mail_html_format) {
        $mail->IsHTML(true);
    }
    if (trim($opac_mail_adresse_from)) {
        $tmp_array_email = explode(';', $opac_mail_adresse_from);
        $mail->From = $tmp_array_email[0];
        if (isset($tmp_array_email[1])) {
            $mail->FromName = $tmp_array_email[1];
        }
    } else {
        $mail->From = $from_mail;
        $mail->FromName = $from_name;
    }
    for ($i = 0; $i < count($destinataires); $i++) {
        $mail->AddAddress($destinataires[$i], $to_nom);
    }
    for ($i = 0; $i < count($destinataires_CC); $i++) {
        $mail->AddCC($destinataires_CC[$i]);
    }
    for ($i = 0; $i < count($destinataires_BCC); $i++) {
        $mail->AddBCC($destinataires_BCC[$i]);
    }
    if ($reply_mail && $reply_name) {
        $mail->AddReplyTo($reply_mail, $reply_name);
    } else {
        $mail->AddReplyTo($from_mail, $from_name);
    }
    $mail->Subject = $obj;
    if ($opac_mail_html_format) {
        if ($faire_nl2br) {
            $mail->Body = wordwrap(nl2br($corps), 70);
        } else {
            $mail->Body = wordwrap($corps, 70);
        }
    } else {
        $corps = str_replace("<hr />", PHP_EOL . "*******************************" . PHP_EOL, $corps);
        $corps = str_replace("<hr />", PHP_EOL . "*******************************" . PHP_EOL, $corps);
        $corps = str_replace("<br />", PHP_EOL, $corps);
        $corps = str_replace("<br />", PHP_EOL, $corps);
        $corps = str_replace(PHP_EOL . PHP_EOL . PHP_EOL, PHP_EOL . PHP_EOL, $corps);
        $corps = strip_tags($corps);
        $corps = html_entity_decode($corps, ENT_QUOTES, $charset);
        $mail->Body = wordwrap($corps, 70);
    }
    for ($i = 0; $i < count($pieces_jointes); $i++) {
        if ($pieces_jointes[$i]["contenu"] && $pieces_jointes[$i]["nomfichier"]) {
            $mail->AddStringAttachment($pieces_jointes[$i]["contenu"], $pieces_jointes[$i]["nomfichier"]);
        }
    }
    if (!$mail->Send()) {
        $retour = false;
        global $error_send_mail;
        $error_send_mail[] = $mail->ErrorInfo;
        // echo $mail->ErrorInfo."<br /><br /><br /><br />";
        // echo $mail->Body ;
    } else {
        $retour = true;
    }
    if ($param[0] == 'smtp') {
        $mail->SmtpClose();
    }
    unset($mail);
    return $retour;
}
Exemple #2
0
function cpg_mail($to, $subject, $msg_body = '', $type = 'text/plain', $sender_name = '', $sender_email = '', $msg_body_plaintext = '')
{
    global $CONFIG, $lang_charset, $HTML_SUBST;
    // makeshift plaintext if not set
    if (!$msg_body_plaintext) {
        $msg_body_plaintext = strip_tags($msg_body);
    }
    // Convert html entities back into normal form for display in non HTML formats
    $msg_body_plaintext = strtr($msg_body_plaintext, array_flip($HTML_SUBST));
    $subject = strtr($subject, array_flip($HTML_SUBST));
    // send mails to ALL admins - not bridged only
    if ($to == 'admin') {
        if (UDB_INTEGRATION == 'coppermine') {
            $to = array($CONFIG['gallery_admin_email']);
            $result = cpg_db_query("SELECT user_email FROM {$CONFIG['TABLE_USERS']} WHERE user_group = 1");
            while ($row = mysql_fetch_assoc($result)) {
                if (!empty($row['user_email'])) {
                    $to[] = $row['user_email'];
                }
            }
            $to = array_unique($to);
        } else {
            $to = array($CONFIG['gallery_admin_email']);
        }
    } else {
        $to = array($to);
    }
    if ($sender_name == '') {
        $sender_name = strtr($CONFIG['gallery_name'], array_flip($HTML_SUBST));
    }
    if ($sender_email == '') {
        $sender_email = $CONFIG['gallery_admin_email'];
    }
    $charset = $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'];
    /**
     * Code to send confirmation email starts
     * Create the mail object
     */
    $mail = new PHPmailer();
    // Set the mail configuration
    if ($CONFIG['smtp_host']) {
        $mail->IsSMTP();
        $mail->Host = $CONFIG['smtp_host'];
        if ($CONFIG['smtp_username']) {
            $mail->SMTPAuth = true;
            $mail->Username = $CONFIG['smtp_username'];
            $mail->Password = $CONFIG['smtp_password'];
        } else {
            $mail->SMTPAuth = false;
        }
    } else {
        $mail->IsMail();
    }
    $mail->IsHTML(true);
    foreach ($to as $email) {
        $mail->AddAddress($email);
    }
    $mail->From = $sender_email;
    $mail->FromName = $sender_name;
    $mail->Subject = $subject;
    $mail->Body = $msg_body;
    $mail->AltBody = $msg_body_plaintext;
    $mail->CharSet = $charset;
    if ($mail->Send()) {
        return 'Mail sent!';
    } else {
        return $mail->ErrorInfo;
    }
}
Exemple #3
0
function cpg_mail($to, $subject, $msg_body = '', $type = 'text/plain', $sender_name = '', $sender_email = '', $msg_body_plaintext = '')
{
    global $CONFIG, $LANG, $CF, $DBS;
    // makeshift plaintext if not set
    if (!$msg_body_plaintext) {
        $msg_body_plaintext = strip_tags($msg_body);
    }
    // Convert html entities back into normal form for display in non HTML formats
    $msg_body_plaintext = strtr($msg_body_plaintext, array_flip($CF->htmlSubst));
    $subject = strtr($subject, array_flip($CF->htmlSubst));
    // send mails to ALL admins - not bridged only
    if ($to == 'admin') {
        $to = array($CONFIG['gallery_admin_email']);
        $results = $DBS->sql_query("SELECT {$DBS->field['user_id']}, {$DBS->field['email']} FROM {$DBS->usertable} WHERE {$DBS->field['user_group']} = 1");
        for ($i = 0; $i < mysql_numrows($results); $i++) {
            print mysql_result($results, $i, $DBS->field['user_id']);
            $to[$i + 1] = mysql_result($results, 0, $DBS->field['email']);
        }
    } else {
        $to = array($to);
    }
    $to = array_unique($to);
    if ($sender_name == '') {
        $sender_name = strtr($CONFIG['gallery_name'], array_flip($CF->htmlSubst));
    }
    if ($sender_email == '') {
        $sender_email = $CONFIG['gallery_admin_email'];
    }
    $charset = $CONFIG['charset'] == 'language file' ? $LANG['charset'] : $CONFIG['charset'];
    /**
     * Code to send confirmation email starts
     * Create the mail object
     */
    $mail = new PHPmailer();
    // Set the mail configuration
    if ($CONFIG['smtp_host']) {
        $mail->IsSMTP();
        $mail->Host = $CONFIG['smtp_host'];
        if ($CONFIG['smtp_username']) {
            $mail->SMTPAuth = true;
            $mail->Username = $CONFIG['smtp_username'];
            $mail->Password = $CONFIG['smtp_password'];
        } else {
            $mail->SMTPAuth = false;
        }
    } else {
        $mail->IsMail();
    }
    $mail->IsHTML(true);
    foreach ($to as $email) {
        $mail->AddAddress($email);
    }
    $mail->From = $sender_email;
    $mail->FromName = $sender_name;
    $mail->Subject = $subject;
    $mail->Body = $msg_body;
    $mail->AltBody = $msg_body_plaintext;
    $mail->CharSet = $charset;
    if ($mail->Send()) {
        return 'Mail sent!';
    } else {
        return $mail->ErrorInfo;
    }
}