Beispiel #1
1
 public function send()
 {
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->SMTPDebug = true;
     // enables SMTP debug information (for testing)
     $mail->SMTPAuth = true;
     // enable SMTP authentication
     $body = $this->body ? $this->body : NULL;
     $title = $this->title ? $this->title : NULL;
     $to = $this->email_to ? $this->email_to : NULL;
     $mail->SMTPSecure = 'tls';
     // sets the prefix to the servier
     $mail->Host = 'smtp.dynect.net';
     // sets GMAIL as the SMTP server
     $mail->Port = 25;
     // set the SMTP port for the GMAIL server
     $mail->Username = '******';
     // GMAIL username
     $mail->Password = '******';
     // GMAIL password
     //$mail->SetFrom('*****@*****.**');
     $mail->SetFrom('*****@*****.**', 'YeahMobi Team');
     //PHP Mailer要求发送的From 与 mail account为同一主机名
     $mail->ClearReplyTos();
     $mail->ClearAddresses();
     $mail->AddReplyTo('*****@*****.**', 'YeahMobi Team');
     $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
     //$mail->AltBody    = $this->_contentReplace($v['title'], $v);                        // optional, comment out and test
     $mail->MsgHTML($body);
     $mail->AddAddress($to);
     $mail->Send();
 }
Beispiel #2
1
 /**
  * Test addressing
  */
 function test_Addressing()
 {
     $this->assertFalse($this->Mail->AddAddress('*****@*****.**'), 'Invalid address accepted');
     $this->assertTrue($this->Mail->AddAddress('*****@*****.**'), 'Addressing failed');
     $this->assertFalse($this->Mail->AddAddress('*****@*****.**'), 'Duplicate addressing failed');
     $this->assertTrue($this->Mail->AddCC('*****@*****.**'), 'CC addressing failed');
     $this->assertFalse($this->Mail->AddCC('*****@*****.**'), 'CC duplicate addressing failed');
     $this->assertFalse($this->Mail->AddCC('*****@*****.**'), 'CC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->AddBCC('*****@*****.**'), 'BCC addressing failed');
     $this->assertFalse($this->Mail->AddBCC('*****@*****.**'), 'BCC duplicate addressing failed');
     $this->assertFalse($this->Mail->AddBCC('*****@*****.**'), 'BCC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->AddReplyTo('*****@*****.**'), 'Replyto Addressing failed');
     $this->assertFalse($this->Mail->AddReplyTo('*****@*****.**'), 'Invalid Replyto address accepted');
     $this->Mail->ClearAddresses();
     $this->Mail->ClearCCs();
     $this->Mail->ClearBCCs();
     $this->Mail->ClearReplyTos();
 }
 function sendQueue($pQueueMixed)
 {
     global $gBitSmarty, $gBitSystem, $gBitLanguage;
     static $body = array();
     if (is_array($pQueueMixed)) {
         $pick = $pQueueMixed;
     } elseif (is_numeric($pQueueMixed)) {
         $pick = $this->mDb->GetRow("SELECT * FROM `" . BIT_DB_PREFIX . "mail_queue` mq WHERE `mail_queue_id` = ? " . $this->mDb->SQLForUpdate(), array($pQueueMixed));
     }
     if (!empty($pick)) {
         $startTime = microtime(TRUE);
         $this->mDb->query("UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `begin_date`=? WHERE `mail_queue_id` = ? ", array(time(), $pick['mail_queue_id']));
         if (!empty($pick['user_id'])) {
             $userHash = $this->mDb->getRow("SELECT * FROM `" . BIT_DB_PREFIX . "users_users` WHERE `user_id`=?", array($pick['user_id']));
             $pick['full_name'] = BitUser::getDisplayName(FALSE, $userHash);
         } else {
             $pick['full_name'] = NULL;
         }
         if (!isset($body[$pick['content_id']])) {
             $gBitSmarty->assign('sending', TRUE);
             // We only support sending of newsletters currently
             $content = new BitNewsletterEdition(NULL, $pick['content_id']);
             if ($content->load()) {
                 $body[$pick['content_id']]['body'] = $content->render();
                 $body[$pick['content_id']]['subject'] = $content->getTitle();
                 $body[$pick['content_id']]['reply_to'] = $content->getField('reply_to', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN']));
                 $body[$pick['content_id']]['object'] = $content;
             } else {
                 bit_error_log($this->mErrors);
             }
             //				$content[$pick['content_id']] = LibertyBase::getLibertyObject();
         }
         print "[ {$pick['mail_queue_id']} ] {$pick['content_id']} TO: {$pick['email']}\t";
         $unsub = $this->getUnsubscription($pick['email'], $pick['nl_content_id']);
         if (!empty($unsub)) {
             print " SKIPPED (unsubscribed) <br/>\n";
             $this->mDb->query("DELETE FROM `" . BIT_DB_PREFIX . "mail_queue` WHERE `mail_queue_id`=?", array($pick['mail_queue_id']));
         } elseif (!empty($body[$pick['content_id']])) {
             $pick['url_code'] = md5($pick['content_id'] . $pick['email'] . $pick['queue_date']);
             $unsub = '';
             if ($body[$pick['content_id']]['object']->mNewsletter->getField('unsub_msg')) {
                 $gBitSmarty->assign('url_code', $pick['url_code']);
             }
             $gBitSystem->preDisplay('');
             $gBitSmarty->assign('sending', TRUE);
             $gBitSmarty->assign('unsubMessage', $unsub);
             $gBitSmarty->assign('trackCode', $pick['url_code']);
             $gBitSmarty->assign('mid', 'bitpackage:newsletters/view_edition.tpl');
             $htmlBody = $gBitSmarty->fetch('bitpackage:newsletters/mail_edition.tpl');
             $htmlBody = bit_add_clickthrough($htmlBody, $pick['url_code']);
             $mailer = new PHPMailer();
             if ($gBitSystem->getConfig('bitmailer_errors_to')) {
                 $mailer->Sender = $gBitSystem->getConfig('bitmailer_errors_to');
                 $mailer->addCustomHeader("Errors-To: " . $gBitSystem->getConfig('bitmailer_errors_to'));
             }
             $mailer->From = $gBitSystem->getConfig('bitmailer_sender_email', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN']));
             $mailer->FromName = $gBitSystem->getConfig('bitmailer_from', $gBitSystem->getConfig('site_title'));
             $mailer->Host = $gBitSystem->getConfig('bitmailer_servers', $gBitSystem->getConfig('kernel_server_name', '127.0.0.1'));
             $mailer->Mailer = $gBitSystem->getConfig('bitmailer_protocol', 'smtp');
             // Alternative to IsSMTP()
             $mailer->CharSet = 'UTF-8';
             if ($gBitSystem->getConfig('bitmailer_smtp_username')) {
                 $mailer->SMTPAuth = TRUE;
                 $mailer->Username = $gBitSystem->getConfig('bitmailer_smtp_username');
             }
             if ($gBitSystem->getConfig('bitmailer_smtp_password')) {
                 $mailer->Password = $gBitSystem->getConfig('bitmailer_smtp_password');
             }
             $mailer->WordWrap = $gBitSystem->getConfig('bitmailer_word_wrap', 75);
             if (!$mailer->SetLanguage($gBitLanguage->getLanguage(), UTIL_PKG_PATH . 'phpmailer/language/')) {
                 $mailer->SetLanguage('en');
             }
             $mailer->ClearReplyTos();
             $mailer->AddReplyTo($body[$pick['content_id']]['reply_to'], $gBitSystem->getConfig('bitmailer_from'));
             $mailer->Body = $htmlBody;
             $mailer->Subject = $body[$pick['content_id']]['subject'];
             $mailer->IsHTML(TRUE);
             $mailer->AltBody = '';
             $mailer->AddAddress($pick['email'], $pick["full_name"]);
             if ($mailer->Send()) {
                 print " SENT " . round(microtime(TRUE) - $startTime, 2) . " secs<br/>\n";
                 flush();
                 $updateQuery = "UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `sent_date`=?,`url_code`=?  WHERE `content_id`=? AND `email`=?";
                 $this->mDb->query($updateQuery, array(time(), $pick['url_code'], $pick['content_id'], $pick['email']));
             } else {
                 $updateQuery = "UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `mail_error`=?,`sent_date`=?  WHERE `content_id`=? AND `email`=?";
                 $this->mDb->query($updateQuery, array($mailer->ErrorInfo, time(), $pick['content_id'], $pick['email']));
                 $pick['error'] = $mailer->ErrorInfo;
                 $this->logError($pick);
             }
         }
     }
 }
Beispiel #4
0
function sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message, $type = "plain", $cc = "", $bcc = "")
{
    global $settings, $locale;
    require_once INCLUDES . "class.phpmailer.php";
    $mail = new PHPMailer();
    if (file_exists(INCLUDES . "language/phpmailer.lang-" . $locale['phpmailer'] . ".php")) {
        $mail->SetLanguage($locale['phpmailer'], INCLUDES . "language/");
    } else {
        $mail->SetLanguage("en", INCLUDES . "language/");
    }
    if (!$settings['smtp_host']) {
        $mail->IsMAIL();
    } else {
        $mail->IsSMTP();
        $mail->Host = $settings['smtp_host'];
        $mail->Port = $settings['smtp_port'];
        $mail->SMTPAuth = $settings['smtp_auth'] ? true : false;
        $mail->Username = $settings['smtp_username'];
        $mail->Password = $settings['smtp_password'];
    }
    $mail->CharSet = $locale['charset'];
    $mail->From = $fromemail;
    $mail->FromName = $fromname;
    $mail->AddAddress($toemail, $toname);
    $mail->AddReplyTo($fromemail, $fromname);
    if ($cc) {
        $cc = explode(", ", $cc);
        foreach ($cc as $ccaddress) {
            $mail->AddCC($ccaddress);
        }
    }
    if ($bcc) {
        $bcc = explode(", ", $bcc);
        foreach ($bcc as $bccaddress) {
            $mail->AddBCC($bccaddress);
        }
    }
    if ($type == "plain") {
        $mail->IsHTML(false);
    } else {
        $mail->IsHTML(true);
    }
    $mail->Subject = $subject;
    $mail->Body = $message;
    if (!$mail->Send()) {
        $mail->ErrorInfo;
        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        return false;
    } else {
        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        return true;
    }
}
 /**
  * Short description of method send
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return int
  */
 public function send()
 {
     $returnValue = (int) 0;
     foreach ($this->messages as $message) {
         if ($message instanceof tao_helpers_transfert_Message) {
             $this->mailer->SetFrom($message->getFrom());
             $this->mailer->AddReplyTo($message->getFrom());
             $this->mailer->Subject = $message->getTitle();
             $this->mailer->AltBody = strip_tags(preg_replace("/<br.*>/i", "\n", $message->getBody()));
             $this->mailer->MsgHTML($message->getBody());
             $this->mailer->AddAddress($message->getTo());
             try {
                 if ($this->mailer->Send()) {
                     $message->setStatus(tao_helpers_transfert_Message::STATUS_SENT);
                     $returnValue++;
                 }
                 if ($this->mailer->IsError()) {
                     if (DEBUG_MODE) {
                         echo $this->mailer->ErrorInfo . "<br>";
                     }
                     $message->setStatus(tao_helpers_transfert_Message::STATUS_ERROR);
                 }
             } catch (phpmailerException $pe) {
                 if (DEBUG_MODE) {
                     print $pe;
                 }
             }
         }
         $this->mailer->ClearReplyTos();
         $this->mailer->ClearAllRecipients();
     }
     $this->mailer->SmtpClose();
     return (int) $returnValue;
 }
Beispiel #6
0
 public function Send(IEmailMessage $emailMessage)
 {
     $this->phpMailer->ClearAllRecipients();
     $this->phpMailer->ClearReplyTos();
     $this->phpMailer->CharSet = $emailMessage->Charset();
     $this->phpMailer->Subject = $emailMessage->Subject();
     $this->phpMailer->Body = $emailMessage->Body();
     $from = $emailMessage->From();
     $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS);
     $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME);
     $address = empty($defaultFrom) ? $from->Address() : $defaultFrom;
     $name = empty($defaultName) ? $from->Name() : $defaultName;
     $this->phpMailer->SetFrom($address, $name);
     $replyTo = $emailMessage->ReplyTo();
     $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name());
     $to = $this->ensureArray($emailMessage->To());
     $toAddresses = new StringBuilder();
     foreach ($to as $address) {
         $toAddresses->Append($address->Address());
         $this->phpMailer->AddAddress($address->Address(), $address->Name());
     }
     $cc = $this->ensureArray($emailMessage->CC());
     foreach ($cc as $address) {
         $this->phpMailer->AddCC($address->Address(), $address->Name());
     }
     $bcc = $this->ensureArray($emailMessage->BCC());
     foreach ($bcc as $address) {
         $this->phpMailer->AddBCC($address->Address(), $address->Name());
     }
     if ($emailMessage->HasStringAttachment()) {
         Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName());
         $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName());
     }
     Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address());
     $success = false;
     try {
         $success = $this->phpMailer->Send();
     } catch (Exception $ex) {
         Log::Error('Failed sending email. Exception: %s', $ex);
     }
     Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo);
 }
Beispiel #7
0
 /**
  * Allows the explicit definition of the email's sender address & name.
  * Defaults to the applications Configuration 'SupportEmail' & 'SupportName'
  * settings respectively.
  *
  * @param string $SenderEmail
  * @param string $SenderName
  * @return Email
  */
 public function From($SenderEmail = '', $SenderName = '', $bOverrideSender = FALSE)
 {
     if ($SenderEmail == '') {
         $SenderEmail = Gdn::Config('Garden.Email.SupportAddress', '');
     }
     if ($SenderName == '') {
         $SenderName = Gdn::Config('Garden.Email.SupportName', '');
     }
     if ($bOverrideSender != FALSE) {
         $this->PhpMailer->ClearReplyTos();
         $this->PhpMailer->Sender = $SenderEmail;
     }
     $this->PhpMailer->SetFrom($SenderEmail, $SenderName);
     return $this;
 }
Beispiel #8
0
/**
 * @param int $action
 */
function send_mail($id_entry, $action, $dformat, $tab_id_moderes = array())
{
    global $vocab, $grrSettings, $locale, $weekstarts, $enable_periods, $periods_name;
    $message_erreur = '';
    // $action = 1 -> Création
    // $action = 2 -> Modification
    // $action = 3 -> Suppression
    // $action = 4 -> Suppression automatique
    // $action = 5 -> réservation en attente de modération
    // $action = 6 -> Résultat d'une décision de modération
    // $action = 7 -> Notification d'un retard dans la restitution d'une ressource.
    require_once 'phpmailer/PHPMailerAutoload.php';
    define('GRR_FROM', Settings::get('grr_mail_from'));
    define('GRR_FROMNAME', Settings::get('grr_mail_fromname'));
    require_once './include/mail.inc.php';
    //$m = new my_phpmailer();
    $mail = new PHPMailer();
    if (Settings::get('grr_mail_method') == 'smtp') {
        $smtpUsername = Settings::get('grr_mail_Username');
        $smtpPassword = Settings::get('grr_mail_Password');
        if ($smtpUsername != "") {
            $mail->SMTPAuth = true;
            $mail->Username = $smtpUsername;
            $mail->Password = $smtpPassword;
        } else {
            $mail->SMTPAuth = false;
        }
        $mail->Host = Settings::get('grr_mail_smtp');
        $mail->Port = 587;
        $mail->isSMTP();
    } else {
        $mail->isSendMail();
    }
    /*    if (Settings::get('grr_mail_method') == 'smtp') {
            $smtpUsername = Settings::get('grr_mail_Username');
            $smtpPassword = Settings::get('grr_mail_Password');
    
            $mail->isSMTP();
        }
    
        if ($smtpUsername != "") {
            $mail->SMTPAuth = true;
            $mail->Username = $smtpUsername;
            $mail->Password = $smtpPassword;
    
        } else {
            $mail->SMTPAuth = true;
        }
    
        $mail->Host = Settings::get('grr_mail_smtp');
        $mail->Port = 587;*/
    $mail->CharSet = 'UTF-8';
    $mail->setFrom(GRR_FROM, GRR_FROMNAME);
    $mail->SetLanguage('fr', './phpmailer/language/');
    setlocale(LC_ALL, $locale);
    $sql = 'SELECT ' . TABLE_PREFIX . '_entry.name,
	' . TABLE_PREFIX . '_entry.description,
	' . TABLE_PREFIX . '_entry.beneficiaire,
	' . TABLE_PREFIX . '_room.room_name,
	' . TABLE_PREFIX . '_area.area_name,
	' . TABLE_PREFIX . '_entry.type,
	' . TABLE_PREFIX . '_entry.room_id,
	' . TABLE_PREFIX . '_entry.repeat_id,
	' . grr_sql_syntax_timestamp_to_unix('' . TABLE_PREFIX . '_entry.timestamp') . ',
	(' . TABLE_PREFIX . '_entry.end_time - ' . TABLE_PREFIX . '_entry.start_time),
	' . TABLE_PREFIX . '_entry.start_time,
	' . TABLE_PREFIX . '_entry.end_time,
	' . TABLE_PREFIX . '_room.area_id,
	' . TABLE_PREFIX . '_room.delais_option_reservation,
	' . TABLE_PREFIX . '_entry.option_reservation,
	' . TABLE_PREFIX . '_entry.moderate,
	' . TABLE_PREFIX . '_entry.beneficiaire_ext,
	' . TABLE_PREFIX . '_entry.jours,
	' . TABLE_PREFIX . '_entry.clef,
	' . TABLE_PREFIX . '_entry.courrier
	FROM ' . TABLE_PREFIX . '_entry, ' . TABLE_PREFIX . '_room, ' . TABLE_PREFIX . '_area
	WHERE ' . TABLE_PREFIX . '_entry.room_id = ' . TABLE_PREFIX . '_room.id
	AND ' . TABLE_PREFIX . '_room.area_id = ' . TABLE_PREFIX . '_area.id
	AND ' . TABLE_PREFIX . "_entry.id='" . protect_data_sql($id_entry) . "'\n\t";
    $res = grr_sql_query($sql);
    if (!$res) {
        fatal_error(0, grr_sql_error());
    }
    if (grr_sql_count($res) < 1) {
        fatal_error(0, get_vocab('invalid_entry_id'));
    }
    $row = grr_sql_row($res, 0);
    grr_sql_free($res);
    get_planning_area_values($row[12]);
    $breve_description = bbcode(removeMailUnicode(htmlspecialchars($row[0])), 'nobbcode');
    $description = bbcode(removeMailUnicode(htmlspecialchars($row[1])), 'nobbcode');
    $beneficiaire = htmlspecialchars($row[2]);
    $room_name = removeMailUnicode(htmlspecialchars($row[3]));
    $area_name = removeMailUnicode(htmlspecialchars($row[4]));
    $room_id = $row[6];
    $area_id = $row[12];
    $repeat_id = $row[7];
    $date_avis = strftime('%Y/%m/%d', $row[10]);
    $startDay = date('d', $row[11]);
    $startMonth = date('m', $row[11]);
    $startYear = date('Y', $row[11]);
    $delais_option_reservation = $row[13];
    $option_reservation = $row[14];
    $moderate = $row[15];
    $beneficiaire_ext = htmlspecialchars($row[16]);
    $jours_cycle = htmlspecialchars($row[17]);
    $duration = $row[9];
    if ($enable_periods == 'y') {
        list($start_period, $start_date) = period_date_string($row[10]);
    } else {
        $start_date = time_date_string($row[10], $dformat);
    }
    $rep_type = 0;
    if ($repeat_id != 0) {
        $res = grr_sql_query('SELECT rep_type, end_date, rep_opt, rep_num_weeks FROM ' . TABLE_PREFIX . "_repeat WHERE id='" . protect_data_sql($repeat_id) . "'");
        if (!$res) {
            fatal_error(0, grr_sql_error());
        }
        $test = grr_sql_count($res);
        if ($test != 1) {
            fatal_error(0, 'Deux reservation on le meme ID.');
        } else {
            $row2 = grr_sql_row($res, 0);
            $rep_type = $row2[0];
            $rep_end_date = strftime($dformat, $row2[1]);
            $rep_opt = $row2[2];
            $rep_num_weeks = $row2[3];
        }
        grr_sql_free($res);
    }
    if ($enable_periods == 'y') {
        toPeriodString($start_period, $duration, $dur_units);
    } else {
        toTimeString($duration, $dur_units);
    }
    $weeklist = array('unused', 'every week', 'week 1/2', 'week 1/3', 'week 1/4', 'week 1/5');
    if ($rep_type == 2) {
        $affiche_period = $vocab[$weeklist[$rep_num_weeks]];
    } else {
        $affiche_period = $vocab['rep_type_' . $rep_type];
    }
    // Le bénéficiaire
    $beneficiaire_email = affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, 'onlymail');
    if ($beneficiaire != '') {
        $beneficiaire_actif = grr_sql_query1('SELECT etat FROM ' . TABLE_PREFIX . "_utilisateurs WHERE login='******'");
        if ($beneficiaire_actif == -1) {
            $beneficiaire_actif = 'actif';
        }
        // Cas des admins
    } elseif ($beneficiaire_ext != '' && $beneficiaire_email != '') {
        $beneficiaire_actif = 'actif';
    } else {
        $beneficiaire_actif = 'inactif';
    }
    // Utilisateur ayant agit sur la réservation
    $user_login = getUserName();
    $user_email = grr_sql_query1('SELECT email FROM ' . TABLE_PREFIX . "_utilisateurs WHERE login='******'");
    //
    // Elaboration du message destiné aux utilisateurs désignés par l'admin dans la partie "Mails automatiques"
    //
    //Nom de l'établissement et mention "mail automatique"
    $message = removeMailUnicode(Settings::get('company')) . ' - ' . $vocab['title_mail'];
    // Url de GRR
    $message = $message . traite_grr_url('', 'y') . "\n\n";
    $sujet = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
    if ($action == 1) {
        $sujet = $sujet . $vocab['subject_mail_creation'];
        $message .= $vocab['the_user'] . affiche_nom_prenom_email($user_login, '', 'formail');
        $message = $message . $vocab['creation_booking'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ") \n";
    } elseif ($action == 2) {
        $sujet = $sujet . $vocab['subject_mail_modify'];
        if ($moderate == 1) {
            $sujet .= ' (' . $vocab['en_attente_moderation'] . ')';
        }
        $message .= $vocab['the_user'] . affiche_nom_prenom_email($user_login, '', 'formail');
        $message = $message . $vocab['modify_booking'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ') ';
    } elseif ($action == 3) {
        $sujet = $sujet . $vocab['subject_mail_delete'];
        if ($moderate == 1) {
            $sujet .= ' (' . $vocab['en_attente_moderation'] . ')';
        }
        $message .= $vocab['the_user'] . affiche_nom_prenom_email($user_login, '', 'formail');
        $message = $message . $vocab['delete_booking'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ") \n";
    } elseif ($action == 4) {
        $sujet = $sujet . $vocab['subject_mail_delete'];
        $message = $message . $vocab['suppression_automatique'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ") \n";
    } elseif ($action == 5) {
        $sujet = $sujet . $vocab['subject_mail_moderation'];
        $message = $message . $vocab['reservation_en_attente_de_moderation'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ") \n";
    } elseif ($action == 6) {
        $sujet = $sujet . $vocab['subject_mail_decision_moderation'];
        $resmoderate = grr_sql_query('SELECT moderate, motivation_moderation FROM ' . TABLE_PREFIX . "_entry_moderate WHERE id ='" . protect_data_sql($id_entry) . "'");
        if (!$resmoderate) {
            fatal_error(0, grr_sql_error());
        }
        if (grr_sql_count($resmoderate) < 1) {
            fatal_error(0, get_vocab('invalid_entry_id'));
        }
        $rowModerate = grr_sql_row($resmoderate, 0);
        grr_sql_free($resmoderate);
        $moderate_decision = $rowModerate[0];
        $moderate_description = $rowModerate[1];
        $message .= $vocab['the_user'] . affiche_nom_prenom_email($user_login, '', 'formail');
        $message = $message . $vocab['traite_moderation'];
        $message = $message . $vocab['the_room'] . $room_name . ' (' . $area_name . ') ';
        $message = $message . $vocab['reservee au nom de'];
        $message = $message . $vocab['the_user'] . affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, 'formail') . " \n";
        if ($moderate_decision == 2) {
            $message .= "\n" . $vocab['moderation_acceptee'];
        } elseif ($moderate_decision == 3) {
            $message .= "\n" . $vocab['moderation_refusee'];
        }
        if ($moderate_description != '') {
            $message .= "\n" . $vocab['motif'] . $vocab['deux_points'];
            $message .= $moderate_description . " \n----";
        }
        $message .= "\n" . $vocab['voir_details'] . $vocab['deux_points'] . "\n";
        if (count($tab_id_moderes) == 0) {
            $message .= "\n" . traite_grr_url('', 'y') . 'view_entry.php?id=' . $id_entry;
        } else {
            foreach ($tab_id_moderes as $id_moderes) {
                $message .= "\n" . traite_grr_url('', 'y') . 'view_entry.php?id=' . $id_moderes;
            }
        }
        $message .= "\n\n" . $vocab['rappel_de_la_demande'] . $vocab['deux_points'] . "\n";
    } elseif ($action == 7) {
        $sujet .= $vocab['subject_mail_retard'];
        $message .= $vocab['message_mail_retard'] . $vocab['deux_points'] . " \n";
        $message .= $room_name . ' (' . $area_name . ") \n";
        $message .= $vocab['nom emprunteur'] . $vocab['deux_points'];
        $message .= affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, 'formail') . " \n";
        if ($beneficiaire_email != '') {
            $message .= $vocab['un email envoye'] . $beneficiaire_email . " \n";
        }
        $message .= "\n" . $vocab['changer statut lorsque ressource restituee'] . $vocab['deux_points'];
        $message .= "\n" . traite_grr_url('', 'y') . 'view_entry.php?id=' . $id_entry . " \n";
    }
    if ($action == 2 || $action == 3) {
        $message = $message . $vocab['reservee au nom de'];
        $message = $message . $vocab['the_user'] . affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, 'formail') . " \n";
    }
    if ($action == 5 || $action == 7) {
        $repondre = Settings::get('webmaster_email');
    } else {
        $repondre = $user_email;
    }
    //
    // Infos sur la réservation
    //
    $reservation = '';
    $reservation = $reservation . $vocab['start_of_the_booking'] . ' ' . $start_date . "\n";
    $reservation = $reservation . $vocab['duration'] . ' ' . $duration . ' ' . $dur_units . "\n";
    if (trim($breve_description) != '') {
        $reservation = $reservation . $vocab['namebooker'] . preg_replace('/ /', ' ', $vocab['deux_points']) . ' ' . $breve_description . "\n";
    } else {
        $reservation = $reservation . $vocab['entryid'] . $room_id . "\n";
    }
    if ($description != '') {
        $reservation = $reservation . $vocab['description'] . ' ' . $description . "\n";
    }
    // Champ additionnel
    $reservation .= affichage_champ_add_mails($id_entry);
    // Type de réservation
    $temp = grr_sql_query1('SELECT type_name FROM ' . TABLE_PREFIX . "_type_area WHERE type_letter='" . $row[5] . "'");
    if ($temp == -1) {
        $temp = '?' . $row[5] . '?';
    } else {
        $temp = removeMailUnicode($temp);
    }
    $reservation = $reservation . $vocab['type'] . preg_replace('/ /', ' ', $vocab['deux_points']) . ' ' . $temp . "\n";
    if ($rep_type != 0) {
        $reservation = $reservation . $vocab['rep_type'] . ' ' . $affiche_period . "\n";
    }
    if ($rep_type != 0) {
        if ($rep_type == 2) {
            $opt = '';
            for ($i = 0; $i < 7; ++$i) {
                $daynum = ($i + $weekstarts) % 7;
                if ($rep_opt[$daynum]) {
                    $opt .= day_name($daynum) . ' ';
                }
            }
            if ($opt) {
                $reservation = $reservation . $vocab['rep_rep_day'] . ' ' . $opt . "\n";
            }
        }
        if ($rep_type == 6) {
            if (Settings::get('jours_cycles_actif') == 'Oui') {
                $reservation = $reservation . $vocab['rep_type_6'] . preg_replace('/ /', ' ', $vocab['deux_points']) . ucfirst(substr($vocab['rep_type_6'], 0, 1)) . $jours_cycle . "\n";
            }
        }
        $reservation = $reservation . $vocab['rep_end_date'] . ' ' . $rep_end_date . "\n";
    }
    if ($delais_option_reservation > 0 && $option_reservation != -1) {
        $reservation = $reservation . '*** ' . $vocab['reservation_a_confirmer_au_plus_tard_le'] . ' ' . time_date_string_jma($option_reservation, $dformat) . " ***\n";
    }
    $reservation = $reservation . "-----\n";
    $message = $message . $reservation;
    $message = $message . $vocab['msg_no_email'] . Settings::get('webmaster_email');
    $message = html_entity_decode($message);
    $sql = 'SELECT u.email FROM ' . TABLE_PREFIX . '_utilisateurs u, ' . TABLE_PREFIX . "_j_mailuser_room j WHERE (j.id_room='" . protect_data_sql($room_id) . "' AND u.login=j.login and u.etat='actif') ORDER BY u.nom, u.prenom";
    $res = grr_sql_query($sql);
    $nombre = grr_sql_count($res);
    if ($nombre > 0) {
        $tab_destinataire = array();
        for ($i = 0; $row = grr_sql_row($res, $i); ++$i) {
            if ($row[0] != '') {
                $tab_destinataire[] = $row[0];
            }
        }
        foreach ($tab_destinataire as $value) {
            if (Settings::get('grr_mail_Bcc') == 'y') {
                $mail->AddBCC($value);
            } else {
                $mail->AddAddress($value);
            }
        }
        $mail->Subject = $sujet;
        $mail->Body = $message;
        $mail->AddReplyTo($repondre);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
    }
    $mail->ClearAddresses();
    $mail->ClearBCCs();
    $mail->ClearReplyTos();
    if ($action == 7) {
        $mail_admin = find_user_room($room_id);
        if (count($mail_admin) > 0) {
            foreach ($mail_admin as $value) {
                if (Settings::get('grr_mail_Bcc') == 'y') {
                    $mail->AddBCC($value);
                } else {
                    $mail->AddAddress($value);
                }
            }
            $mail->Subject = $sujet;
            $mail->Body = $message;
            $mail->AddReplyTo($repondre);
            if (!$mail->Send()) {
                $message_erreur .= $mail->ErrorInfo;
            }
        }
        $mail->ClearAddresses();
        $mail->ClearBCCs();
        $mail->ClearReplyTos();
    }
    if ($action == 7) {
        $sujet7 = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
        $sujet7 .= $vocab['subject_mail_retard'];
        $message7 = removeMailUnicode(Settings::get('company')) . ' - ' . $vocab['title_mail'];
        $message7 .= traite_grr_url('', 'y') . "\n\n";
        $message7 .= $vocab['ressource empruntee non restituée'] . "\n";
        $message7 .= $room_name . ' (' . $area_name . ')';
        $message7 .= "\n" . $reservation;
        $message7 = html_entity_decode($message7);
        $destinataire7 = $beneficiaire_email;
        $repondre7 = Settings::get('webmaster_email');
        $mail->AddAddress($destinataire7);
        $mail->Subject = $sujet7;
        $mail->Body = $message7;
        $mail->AddReplyTo($repondre7);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 4) {
        $destinataire4 = $beneficiaire_email;
        $repondre4 = Settings::get('webmaster_email');
        $mail->AddAddress($destinataire4);
        $mail->Subject = $sujet;
        $mail->Body = $message;
        $mail->AddReplyTo($repondre4);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 5) {
        $mail_admin = find_user_room($room_id);
        if (count($mail_admin) > 0) {
            foreach ($mail_admin as $value) {
                if (Settings::get('grr_mail_Bcc') == 'y') {
                    $mail->AddBCC($value);
                } else {
                    $mail->AddAddress($value);
                }
            }
            $sujet5 = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
            $sujet5 .= $vocab['subject_mail_moderation'];
            $message5 = removeMailUnicode(Settings::get('company')) . ' - ' . $vocab['title_mail'];
            $message5 .= traite_grr_url('', 'y') . "\n\n";
            $message5 .= $vocab['subject_a_moderer'];
            //$message5 .= "\n".traite_grr_url('', 'y').'view_entry.php?id='.$id_entry;
            /* changing view entry for the day view, to have quick look around the entry to modify*/
            $message5 .= "\n" . traite_grr_url('', 'y') . 'week.php?year=' . $startYear . '&month=' . $startMonth . '&day=' . $startDay . '&room=' . $room_id;
            $message5 .= "\n\n" . $vocab['created_by'] . affiche_nom_prenom_email($user_login, '', 'formail');
            $message5 .= "\n" . $vocab['room'] . $vocab['deux_points'] . $room_name . ' (' . $area_name . ") \n";
            $message5 = html_entity_decode($message5);
            $repondre5 = Settings::get('webmaster_email');
            $mail->Subject = $sujet5;
            $mail->Body = $message5;
            $mail->AddReplyTo($repondre5);
            if (!$mail->Send()) {
                $message_erreur .= $mail->ErrorInfo;
            }
        }
        $mail->ClearAddresses();
        $mail->ClearBCCs();
        $mail->ClearReplyTos();
    }
    if ($action == 5 && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet5 = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
        $sujet5 .= $vocab['subject_mail_moderation'];
        $message5 = removeMailUnicode(Settings::get('company')) . ' - ' . $vocab['title_mail'];
        $message5 .= traite_grr_url('', 'y') . "\n\n";
        $message5 .= $vocab['texte_en_attente_de_moderation'];
        $message5 .= "\n" . $vocab['rappel_de_la_demande'] . $vocab['deux_points'];
        $message5 .= "\n" . $vocab['the_room'] . $room_name . ' (' . $area_name . ')';
        $message5 .= "\n" . $reservation;
        $message5 = html_entity_decode($message5);
        $destinataire5 = $beneficiaire_email;
        $repondre5 = Settings::get('webmaster_email');
        $mail->AddAddress($destinataire5);
        $mail->Subject = $sujet5;
        $mail->Body = $message5;
        $mail->AddReplyTo($repondre5);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 6 && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet6 = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
        $sujet6 .= $vocab['subject_mail_decision_moderation'];
        $message6 = $message;
        $destinataire6 = $beneficiaire_email;
        $repondre6 = $user_email;
        $mail->AddAddress($destinataire6);
        $mail->Subject = $sujet6;
        $mail->Body = $message6;
        $mail->AddReplyTo($repondre6);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    // Cas d'une création, modification ou suppression d'un message par un utilisateur différent du bénéficiaire :
    // On envoie un message au bénéficiaire de la réservation pour l'avertir d'une modif ou d'une suppression
    if (($action == 1 || $action == 2 || $action == 3) && (strtolower($user_login) != strtolower($beneficiaire) || Settings::get('send_always_mail_to_creator') == '1') && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet2 = $vocab['subject_mail1'] . $room_name . ' - ' . $date_avis;
        $message2 = removeMailUnicode(Settings::get('company')) . ' - ' . $vocab['title_mail'];
        $message2 = $message2 . traite_grr_url('', 'y') . "\n\n";
        $message2 = $message2 . $vocab['the_user'] . affiche_nom_prenom_email($user_login, '', 'formail');
        if ($action == 1) {
            $sujet2 = $sujet2 . $vocab['subject_mail_creation'];
            $message2 = $message2 . $vocab['creation_booking_for_you'];
            $message2 = $message2 . $vocab['the_room'] . $room_name . ' (' . $area_name . ').';
        } elseif ($action == 2) {
            $sujet2 = $sujet2 . $vocab['subject_mail_modify'];
            $message2 = $message2 . $vocab['modify_booking'];
            $message2 = $message2 . $vocab['the_room'] . $room_name . ' (' . $area_name . ')';
            $message2 = $message2 . $vocab['created_by_you'];
        } else {
            $sujet2 = $sujet2 . $vocab['subject_mail_delete'];
            $message2 = $message2 . $vocab['delete_booking'];
            $message2 = $message2 . $vocab['the_room'] . $room_name . ' (' . $area_name . ')';
            $message2 = $message2 . $vocab['created_by_you'];
        }
        $message2 = $message2 . "\n" . $reservation;
        $message2 = html_entity_decode($message2);
        $destinataire2 = $beneficiaire_email;
        $repondre2 = $user_email;
        $mail->AddAddress($destinataire2);
        $mail->Subject = $sujet2;
        $mail->Body = $message2;
        $mail->AddReplyTo($repondre2);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    return $message_erreur;
}
 static function old_send_email($to, $subject, $html, $text, $istest = false, $sid, $list_id, $report_id)
 {
     global $phpmailer, $wpdb;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer();
     }
     /*
      * Make sure the mailer thingy is clean before we start,  should not
      * be necessary, but who knows what others are doing to our mailer
      */
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     //return $email;
     //
     $charset = SendPress_Option::get('email-charset', 'UTF-8');
     $encoding = SendPress_Option::get('email-encoding', '8bit');
     $phpmailer->CharSet = $charset;
     $phpmailer->Encoding = $encoding;
     if ($charset != 'UTF-8') {
         $sender = new SendPress_Sender();
         $html = $sender->change($html, 'UTF-8', $charset);
         $text = $sender->change($text, 'UTF-8', $charset);
         $subject = $sender->change($subject, 'UTF-8', $charset);
     }
     $subject = str_replace(array('’', '“', '�', '–'), array("'", '"', '"', '-'), $subject);
     $html = str_replace(chr(194), chr(32), $html);
     $text = str_replace(chr(194), chr(32), $text);
     $phpmailer->AddAddress(trim($to));
     $phpmailer->AltBody = $text;
     $phpmailer->Subject = $subject;
     $phpmailer->MsgHTML($html);
     $content_type = 'text/html';
     $phpmailer->ContentType = $content_type;
     // Set whether it's plaintext, depending on $content_type
     //if ( 'text/html' == $content_type )
     $phpmailer->IsHTML(true);
     /**
      * We'll let php init mess with the message body and headers.  But then
      * we stomp all over it.  Sorry, my plug-inis more important than yours :)
      */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     $from_email = SendPress_Option::get('fromemail');
     $phpmailer->From = $from_email;
     $phpmailer->FromName = SendPress_Option::get('fromname');
     $phpmailer->Sender = SendPress_Option::get('fromemail');
     $sending_method = SendPress_Option::get('sendmethod');
     $phpmailer = apply_filters('sendpress_sending_method_' . $sending_method, $phpmailer);
     $hdr = new SendPress_SendGrid_SMTP_API();
     $hdr->addFilterSetting('dkim', 'domain', SendPress_Manager::get_domain_from_email($from_email));
     $phpmailer->AddCustomHeader(sprintf('X-SMTPAPI: %s', $hdr->asJSON()));
     $phpmailer->AddCustomHeader('X-SP-METHOD: old');
     // Set SMTPDebug to 2 will collect dialogue between us and the mail server
     if ($istest == true) {
         $phpmailer->SMTPDebug = 2;
         // Start output buffering to grab smtp output
         ob_start();
     }
     // Send!
     $result = true;
     // start with true, meaning no error
     $result = @$phpmailer->Send();
     //$phpmailer->SMTPClose();
     if ($istest == true) {
         // Grab the smtp debugging output
         $smtp_debug = ob_get_clean();
         SendPress_Option::set('phpmailer_error', $phpmailer->ErrorInfo);
         SendPress_Option::set('last_test_debug', $smtp_debug);
     }
     if ($result != true && $istest == true) {
         $hostmsg = 'host: ' . $phpmailer->Host . '  port: ' . $phpmailer->Port . '  secure: ' . $phpmailer->SMTPSecure . '  auth: ' . $phpmailer->SMTPAuth . '  user: '******'';
         $msg .= __('The result was: ', 'sendpress') . $result . "\n";
         $msg .= __('The mailer error info: ', 'sendpress') . $phpmailer->ErrorInfo . "\n";
         $msg .= $hostmsg;
         $msg .= __("The SMTP debugging output is shown below:\n", "sendpress");
         $msg .= $smtp_debug . "\n";
     }
     return $result;
 }
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'bb_mail_from' and 'bb_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'bb_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'bb_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'bb_mail_charset' filter.
  *
  * @uses apply_filters() Calls 'bb_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'bb_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'bb_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'bb_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'bb_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'bb_phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  *
  * @param string $to Email address to send message
  * @param string $subject Email subject
  * @param string $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @param string|array $attachments Optional. Files to attach.
  * @return bool Whether the email contents were sent successfully.
  */
 function bb_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('bb_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", $attachments);
     }
     global $bb_phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($bb_phpmailer) || !is_a($bb_phpmailer, 'PHPMailer')) {
         require_once BACKPRESS_PATH . 'class.mailer.php';
         require_once BACKPRESS_PATH . 'class.mailer-smtp.php';
         $bb_phpmailer = new PHPMailer();
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = (array) explode("\n", $headers);
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 // Mainly for legacy -- process a From: header if it's there
                 if ('from' == strtolower($name)) {
                     if (strpos($content, '<') !== false) {
                         // So... making my life hard again?
                         $from_name = substr($content, 0, strpos($content, '<') - 1);
                         $from_name = str_replace('"', '', $from_name);
                         $from_name = trim($from_name);
                         $from_email = substr($content, strpos($content, '<') + 1);
                         $from_email = str_replace('>', '', $from_email);
                         $from_email = trim($from_email);
                     } else {
                         $from_email = trim($content);
                     }
                 } elseif ('content-type' == strtolower($name)) {
                     if (strpos($content, ';') !== false) {
                         list($type, $charset) = explode(';', $content);
                         $content_type = trim($type);
                         if (false !== stripos($charset, 'charset=')) {
                             $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                         } elseif (false !== stripos($charset, 'boundary=')) {
                             $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset));
                             $charset = '';
                         }
                     } else {
                         $content_type = trim($content);
                     }
                 } elseif ('cc' == strtolower($name)) {
                     $cc = explode(",", $content);
                 } elseif ('bcc' == strtolower($name)) {
                     $bcc = explode(",", $content);
                 } else {
                     // Add it to our grand headers array
                     $headers[trim($name)] = trim($content);
                 }
             }
         }
     }
     // Empty out the values that may be set
     $bb_phpmailer->ClearAddresses();
     $bb_phpmailer->ClearAllRecipients();
     $bb_phpmailer->ClearAttachments();
     $bb_phpmailer->ClearBCCs();
     $bb_phpmailer->ClearCCs();
     $bb_phpmailer->ClearCustomHeaders();
     $bb_phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = bb_get_option('name');
     }
     // If we don't have an email from the input headers
     if (!isset($from_email)) {
         $from_email = bb_get_option('from_email');
     }
     // If there is still no email address
     if (!$from_email) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'bbpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $bb_phpmailer->From = apply_filters('bb_mail_from', $from_email);
     $bb_phpmailer->FromName = apply_filters('bb_mail_from_name', $from_name);
     // Set destination address
     $bb_phpmailer->AddAddress($to);
     // Set mail's subject and body
     $bb_phpmailer->Subject = $subject;
     $bb_phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             $bb_phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             $bb_phpmailer->AddBcc(trim($recipient));
         }
     }
     // Set to use PHP's mail()
     $bb_phpmailer->IsMail();
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/plain';
     }
     $content_type = apply_filters('bb_mail_content_type', $content_type);
     $bb_phpmailer->ContentType = $content_type;
     // Set whether it's plaintext or not, depending on $content_type
     if ($content_type == 'text/html') {
         $bb_phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = bb_get_option('charset');
     }
     // Set the content-type and charset
     $bb_phpmailer->CharSet = apply_filters('bb_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $bb_phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $bb_phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $bb_phpmailer->AddAttachment($attachment);
         }
     }
     do_action_ref_array('bb_phpmailer_init', array(&$bb_phpmailer));
     // Send!
     $result = @$bb_phpmailer->Send();
     return $result;
 }
Beispiel #11
0
/**
* Send an email with report output
*
* This function will send email to the user who set up the
* scan, and optionally, a list of recipients who should also
* receive the scan output. See further inline comments for
* details on how the email is sent to the multiple recipients.
* It's actually pretty deviant :-)
*
* @param string $to Email of the person who created the scan
* @param array $rcpts Optional list of secondary recipients of the email
* @param string $subj The subject line of the email
* @param string $body The contents of the body of the email. This
*	will likely be the full output of the report
* @param string $format The format of the email that is going
*	to be sent. This is important to specify because different
*	MIME headers in the email will be sent depending on the
*	format specifed. For example, if you send this function
*	a body composed of HTML, but specify the format as 'text',
*	the user will receive a text email exposing all the HTML
*	tags. As such, they'll probably be really confused.
*/
function send_email($to, $rcpts = '', $subj = '', $body = '', $format = 'html')
{
    require_once _ABSPATH . '/lib/phpmailer/class.phpmailer.php';
    /**
     * Normally, only a single recipient gets an email.
     *
     * The user can also specify a list of individuals to
     * receive a CC of the email. This list is the $rcpts
     * variable.
     *
     * If multiple recipients are specified, the user will
     * receive an email from nightwatch containing the scan
     * results. All the recipients though will receive an
     * email from the user. This is kinda like keeping tabs
     * on the user so that they dont spam. Also, it provides
     * a rudimentary means of accountability because any
     * recipients will redirect questions and comments they
     * have, back to the original user and not to nightwatch
     */
    if ($rcpts == '') {
        $smtp = new PHPMailer();
        $smtp->IsSMTP();
        $smtp->Host = _SMTP_SERVER;
        $smtp->SMTPAuth = _SMTP_AUTH;
        $smtp->From = _SMTP_FROM;
        $smtp->FromName = _SMTP_FROM_NAME;
        $smtp->AddAddress($to);
        $smtp->AddReplyTo(_SMTP_FROM, _SMTP_FROM_NAME);
        if ($format == 'html') {
            $smtp->IsHTML(true);
        } else {
            $smtp->IsHTML(false);
        }
        $smtp->Subject = $subj;
        $smtp->Body = $body;
        $smtp->Send();
    } else {
        // First, send it to the user who made the scan
        $smtp = new PHPMailer();
        $smtp->IsSMTP();
        $smtp->Host = _SMTP_SERVER;
        $smtp->SMTPAuth = _SMTP_AUTH;
        $smtp->From = _SMTP_FROM;
        $smtp->FromName = _SMTP_FROM_NAME;
        $smtp->AddAddress($to);
        $smtp->AddReplyTo(_SMTP_FROM, _SMTP_FROM_NAME);
        if ($format == 'html') {
            $smtp->IsHTML(true);
        } else {
            $smtp->IsHTML(false);
        }
        $smtp->Subject = $subj;
        $smtp->Body = $body;
        $smtp->Send();
        // Clear the recipients and start new mail
        $smtp->ClearAllRecipients();
        $smtp->ClearReplyTos();
        /**
         * Now, send the same email to their recipient list
         * spoofing the 'from' field to be the user who made
         * the scan
         */
        $smtp->From = $to;
        $smtp->FromName = $to;
        $smtp->AddReplyTo($to, $to);
        if ($format == 'html') {
            $smtp->IsHTML(true);
        } else {
            $smtp->IsHTML(false);
        }
        // Send to all the recipients
        foreach ($rcpts as $key => $rcpt) {
            if ($rcpt == '') {
                continue;
            }
            $smtp->AddAddress($rcpt);
            $smtp->Send();
            $smtp->ClearAllRecipients();
        }
    }
}
Beispiel #12
0
 public function sendMail()
 {
     /** 载入邮件组件 */
     require_once $this->_dir . '/lib/class.phpmailer.php';
     $mailer = new PHPMailer();
     $mailer->CharSet = 'UTF-8';
     $mailer->Encoding = 'base64';
     //选择发信模式
     switch ($this->_cfg->mode) {
         case 'mail':
             break;
         case 'sendmail':
             $mailer->IsSendmail();
             break;
         case 'smtp':
             $mailer->IsSMTP();
             if (in_array('validate', $this->_cfg->validate)) {
                 $mailer->SMTPAuth = true;
             }
             if (in_array('ssl', $this->_cfg->validate)) {
                 $mailer->SMTPSecure = "ssl";
             }
             $mailer->Host = $this->_cfg->host;
             $mailer->Port = $this->_cfg->port;
             $mailer->Username = $this->_cfg->user;
             $mailer->Password = $this->_cfg->pass;
             break;
     }
     $mailer->SetFrom($this->_email->from, $this->_email->fromName);
     $mailer->AddReplyTo($this->_email->to, $this->_email->toName);
     $mailer->Subject = $this->_email->subject;
     $mailer->AltBody = $this->_email->altBody;
     $mailer->MsgHTML($this->_email->msgHtml);
     $mailer->AddAddress($this->_email->to, $this->_email->toName);
     if ($result = $mailer->Send()) {
         $this->mailLog();
     } else {
         $this->mailLog(false, $mailer->ErrorInfo . "\r\n");
         $result = $mailer->ErrorInfo;
     }
     $mailer->ClearAddresses();
     $mailer->ClearReplyTos();
     return $result;
 }
Beispiel #13
0
function osc_sendMail($params)
{
    // DO NOT send mail if it's a demo
    if (defined('DEMO')) {
        return false;
    }
    $mail = new PHPMailer(true);
    $mail->ClearAddresses();
    $mail->ClearAllRecipients();
    $mail->ClearAttachments();
    $mail->ClearBCCs();
    $mail->ClearCCs();
    $mail->ClearCustomHeaders();
    $mail->ClearReplyTos();
    $mail = osc_apply_filter('init_send_mail', $mail, $params);
    if (osc_mailserver_pop()) {
        require_once osc_lib_path() . 'phpmailer/class.pop3.php';
        $pop = new POP3();
        $pop3_host = osc_mailserver_host();
        if (array_key_exists('host', $params)) {
            $pop3_host = $params['host'];
        }
        $pop3_port = osc_mailserver_port();
        if (array_key_exists('port', $params)) {
            $pop3_port = $params['port'];
        }
        $pop3_username = osc_mailserver_username();
        if (array_key_exists('username', $params)) {
            $pop3_username = $params['username'];
        }
        $pop3_password = osc_mailserver_password();
        if (array_key_exists('password', $params)) {
            $pop3_password = $params['password'];
        }
        $pop->Authorise($pop3_host, $pop3_port, 30, $pop3_username, $pop3_password, 0);
    }
    if (osc_mailserver_auth()) {
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
    } else {
        if (osc_mailserver_pop()) {
            $mail->IsSMTP();
        }
    }
    $smtpSecure = osc_mailserver_ssl();
    if (array_key_exists('password', $params)) {
        $smtpSecure = $params['ssl'];
    }
    if ($smtpSecure != '') {
        $mail->SMTPSecure = $smtpSecure;
    }
    $stmpUsername = osc_mailserver_username();
    if (array_key_exists('username', $params)) {
        $stmpUsername = $params['username'];
    }
    if ($stmpUsername != '') {
        $mail->Username = $stmpUsername;
    }
    $smtpPassword = osc_mailserver_password();
    if (array_key_exists('password', $params)) {
        $smtpPassword = $params['password'];
    }
    if ($smtpPassword != '') {
        $mail->Password = $smtpPassword;
    }
    $smtpHost = osc_mailserver_host();
    if (array_key_exists('host', $params)) {
        $smtpHost = $params['host'];
    }
    if ($smtpHost != '') {
        $mail->Host = $smtpHost;
    }
    $smtpPort = osc_mailserver_port();
    if (array_key_exists('port', $params)) {
        $smtpPort = $params['port'];
    }
    if ($smtpPort != '') {
        $mail->Port = $smtpPort;
    }
    $from = osc_mailserver_mail_from();
    if (empty($from)) {
        $from = 'osclass@' . osc_get_domain();
        if (array_key_exists('from', $params)) {
            $from = $params['from'];
        }
    }
    $from_name = osc_mailserver_name_from();
    if (empty($from_name)) {
        $from_name = osc_page_title();
        if (array_key_exists('from_name', $params)) {
            $from_name = $params['from_name'];
        }
    }
    $mail->From = osc_apply_filter('mail_from', $from, $params);
    $mail->FromName = osc_apply_filter('mail_from_name', $from_name, $params);
    $to = $params['to'];
    $to_name = '';
    if (array_key_exists('to_name', $params)) {
        $to_name = $params['to_name'];
    }
    if (!is_array($to)) {
        $to = array($to => $to_name);
    }
    foreach ($to as $to_email => $to_name) {
        try {
            $mail->addAddress($to_email, $to_name);
        } catch (phpmailerException $e) {
            continue;
        }
    }
    if (array_key_exists('add_bcc', $params)) {
        if (!is_array($params['add_bcc']) && $params['add_bcc'] != '') {
            $params['add_bcc'] = array($params['add_bcc']);
        }
        foreach ($params['add_bcc'] as $bcc) {
            try {
                $mail->AddBCC($bcc);
            } catch (phpmailerException $e) {
                continue;
            }
        }
    }
    if (array_key_exists('reply_to', $params)) {
        try {
            $mail->AddReplyTo($params['reply_to']);
        } catch (phpmailerException $e) {
            //continue;
        }
    }
    $mail->Subject = $params['subject'];
    $mail->Body = $params['body'];
    if (array_key_exists('attachment', $params)) {
        if (!is_array($params['attachment']) || isset($params['attachment']['path'])) {
            $params['attachment'] = array($params['attachment']);
        }
        foreach ($params['attachment'] as $attachment) {
            try {
                if (is_array($attachment)) {
                    if (isset($attachment['path']) && isset($attachment['name'])) {
                        $mail->AddAttachment($attachment['path'], $attachment['name']);
                    }
                } else {
                    $mail->AddAttachment($attachment);
                }
            } catch (phpmailerException $e) {
                continue;
            }
        }
    }
    $mail->CharSet = 'utf-8';
    $mail->IsHTML(true);
    $mail = osc_apply_filter('pre_send_mail', $mail, $params);
    // send email!
    try {
        $mail->Send();
    } catch (phpmailerException $e) {
        return false;
    }
    return true;
}
Beispiel #14
0
 public function send_email_campaign($sender_data, $receiver_data, $template_data, $user_config)
 {
     $this->load->library('My_PHPMailer');
     $setup = array("smtp_host" => $user_config['smtp_host'], "smtp_port" => $user_config['smtp_port'], "smtp_protocol" => "TLS", "smtp_auth" => true, "smtp_username" => $user_config['smtp_username'], "smtp_password" => $user_config['smtp_password']);
     $mail = new PHPMailer();
     $mail->XMailer = 'PHP ';
     $mail->CharSet = 'UTF-8';
     //$mail->SMTPDebug = 3; // Enable verbose debug output
     $mail->isSMTP();
     // Set mailer to use SMTP
     $mail->Host = $setup['smtp_host'];
     // Specify main and backup SMTP servers  'smtp1.example.com;smtp2.example.com'
     $mail->SMTPAuth = $setup['smtp_auth'] ? true : false;
     // Enable SMTP authentication
     $mail->Username = $setup['smtp_username'];
     // SMTP username
     $mail->Password = $setup['smtp_password'];
     // SMTP password
     $mail->SMTPSecure = $setup['smtp_protocol'];
     // Enable TLS encryption, `ssl` also accepted
     $mail->Port = $setup['smtp_port'];
     // TCP port to connect to
     $mail->ClearAllRecipients();
     $mail->ClearAddresses();
     $mail->ClearCCs();
     $mail->ClearBCCs();
     $mail->ClearReplyTos();
     $mail->ClearAttachments();
     $mail->ClearCustomHeaders();
     $mail->From = $sender_data['email'];
     $mail->FromName = $sender_data['name'];
     $mail->addAddress($receiver_data['email'], $receiver_data['name']);
     // Add a recipient
     $mail->addReplyTo($sender_data['email'], '');
     $mail->isHTML(true);
     // Set email format to HTML
     $body = $this->load->view('email/campaign_email', array('template_data' => $template_data), true);
     $mail->Subject = $template_data['subject'];
     $mail->Body = $body;
     // html mail
     $mail->AltBody = $body;
     // Plain text mail
     // For most clients expecting the Priority header:
     // 1 = High, 2 = Medium, 3 = Low
     $mail->Priority = 1;
     // MS Outlook custom header
     // May set to "Urgent" or "Highest" rather than "High"
     $mail->AddCustomHeader("X-MSMail-Priority: High");
     // Not sure if Priority will also set the Importance header:
     $mail->AddCustomHeader("Importance: High");
     $mail->AddCustomHeader("X-Sender: <{''}>\n");
     $mail->addCustomHeader("List-Unsubscribe", "<mailto:unsubscribe@digibuzz24.net/unsubscribe.php?email='" . $sender_data['email'] . "'>");
     $mail->addCustomHeader("List-Subscribe", "<mailto:subscribe@digibuzz24.net/subscribe.php?email='" . $sender_data['email'] . "'>");
     $mail->addCustomHeader("List-Owner", "<mailto:admin@digibuzz24.net>");
     // Uncomment this
     if ($mail->send()) {
         return 'ok';
     } else {
         //echo 'Mailer Error: ' . $mail->ErrorInfo; exit;
         return 'error';
     }
 }
Beispiel #15
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @param string|array $to Array or comma-separated list of email addresses to send message.
  * @param string $subject Email subject
  * @param string $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @param string|array $attachments Optional. Files to attach.
  * @return bool Whether the email contents were sent successfully.
  */
 function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once BACKPRESS_PATH . '/class.mailer.php';
         require_once BACKPRESS_PATH . '/class.mailer-smtp.php';
         $phpmailer = new PHPMailer();
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 switch (strtolower($name)) {
                     // Mainly for legacy -- process a From: header if it's there
                     case 'from':
                         if (strpos($content, '<') !== false) {
                             // So... making my life hard again?
                             $from_name = substr($content, 0, strpos($content, '<') - 1);
                             $from_name = str_replace('"', '', $from_name);
                             $from_name = trim($from_name);
                             $from_email = substr($content, strpos($content, '<') + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                         } else {
                             $from_email = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (strpos($content, ';') !== false) {
                             list($type, $charset) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                             } elseif (false !== stripos($charset, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset));
                                 $charset = '';
                             }
                         } else {
                             $content_type = trim($content);
                         }
                         break;
                     case 'cc':
                         $cc = array_merge((array) $cc, explode(',', $content));
                         break;
                     case 'bcc':
                         $bcc = array_merge((array) $bcc, explode(',', $content));
                         break;
                     case 'message-id':
                         $message_id = trim($content);
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* If we don't have an email from the input headers default to wordpress@$sitename
      * Some hosts will block outgoing mail from this address if it doesn't exist but
      * there's no easy alternative. Defaulting to admin_email might appear to be another
      * option but some hosts may refuse to relay mail from an unknown domain. See
      * http://trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     foreach ((array) $to as $recipient) {
         $phpmailer->AddAddress(trim($recipient));
     }
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             $phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             $phpmailer->AddBcc(trim($recipient));
         }
     }
     if (!empty($message_id)) {
         $phpmailer->MessageID = $message_id;
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // SupportPress: use STMP if configured
     if (defined('SMTP_HOST') && SMTP_HOST) {
         $phpmailer->IsSMTP();
         $phpmailer->Host = SMTP_HOST;
         if (SMTP_PORT) {
             $phpmailer->Host .= ':' . SMTP_PORT;
         }
         global $email_domain;
         $phpmailer->Hostname = $email_domain;
         if (SMTP_USER) {
             $phpmailer->SMTPAuth = true;
             $phpmailer->Username = SMTP_USER;
             $phpmailer->Password = SMTP_PASSWORD;
         }
     }
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/plain';
     }
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     $phpmailer->ContentType = $content_type;
     // Set whether it's plaintext, depending on $content_type
     if ('text/html' == $content_type) {
         $phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = 'utf-8';
     }
     // Set the content-type and charset
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $phpmailer->AddAttachment($attachment);
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     $result = @$phpmailer->Send();
     return $result;
 }
Beispiel #16
0
 /**
  * Transfers the email headers to PHPMailer.
  *
  * @access protected
  * @param PHPMailer $mailer
  * @throws MailerException
  * @throws phpmailerException
  */
 protected function transferHeaders(PHPMailer &$mailer)
 {
     // will throw an exception if an error occurs; will let it bubble up
     $headers = $this->headers->packageHeaders();
     foreach ($headers as $key => $value) {
         switch ($key) {
             case EmailHeaders::From:
                 if (!empty($value[1])) {
                     // perform character set and HTML character translations on the From name
                     $value[1] = $this->formatter->translateCharacters($value[1], $this->config->getLocale(), $this->config->getCharset());
                 }
                 // set PHPMailer's From so that PHPMailer can correctly construct the From header at send time
                 try {
                     $mailer->SetFrom($value[0], $value[1]);
                 } catch (Exception $e) {
                     throw new MailerException("Failed to add the " . EmailHeaders::From . " header: " . $e->getMessage(), MailerException::FailedToTransferHeaders);
                 }
                 break;
             case EmailHeaders::ReplyTo:
                 // only allow PHPMailer to automatically set the Reply-To if this header isn't provided
                 // so clear PHPMailer's Reply-To array if this header is provided
                 $mailer->ClearReplyTos();
                 if (!empty($value[1])) {
                     // perform character set and HTML character translations on the Reply-To name
                     $value[1] = $this->formatter->translateCharacters($value[1], $this->config->getLocale(), $this->config->getCharset());
                 }
                 // set PHPMailer's ReplyTo so that PHPMailer can correctly construct the Reply-To header at send
                 // time
                 try {
                     // PHPMailer's AddReplyTo could return true or false or allow an exception to bubble up. We
                     // want the same behavior to be applied for both false and on error, so throw a
                     // phpMailerException on failure.
                     if (!$mailer->AddReplyTo($value[0], $value[1])) {
                         // doesn't matter what the message is since we're going to eat phpmailerExceptions
                         throw new phpmailerException();
                     }
                 } catch (Exception $e) {
                     throw new MailerException("Failed to add the " . EmailHeaders::ReplyTo . " header: " . $e->getMessage(), MailerException::FailedToTransferHeaders);
                 }
                 break;
             case EmailHeaders::Sender:
                 // set PHPMailer's Sender so that PHPMailer can correctly construct the Sender header at send time
                 $mailer->Sender = $value;
                 break;
             case EmailHeaders::MessageId:
                 // set PHPMailer's MessageId so that PHPMailer can correctly construct the Message-ID header at
                 // send time
                 $mailer->MessageID = $value;
                 break;
             case EmailHeaders::Priority:
                 // set PHPMailer's Priority so that PHPMailer can correctly construct the Priority header at send
                 // time
                 $mailer->Priority = $value;
                 break;
             case EmailHeaders::DispositionNotificationTo:
                 // set PHPMailer's ConfirmReadingTo so that PHPMailer can correctly construct the
                 // Disposition-Notification-To header at send time
                 $mailer->ConfirmReadingTo = $value;
                 break;
             case EmailHeaders::Subject:
                 // perform character set and HTML character translations on the subject
                 $value = $this->formatter->translateCharacters($value, $this->config->getLocale(), $this->config->getCharset());
                 // set PHPMailer's Subject so that PHPMailer can correctly construct the Subject header at send time
                 $mailer->Subject = $value;
                 break;
             default:
                 // it's not known, so it must be a custom header; add it to PHPMailer's custom headers array
                 //TODO: any need for charset translations for from_html on the value?
                 $mailer->AddCustomHeader($key, $value);
                 break;
         }
     }
 }
Beispiel #17
0
            $mail->MsgHTML(str_replace('<!--%htmlEmailIntro%-->', $htmlEmailIntro, $htmlMessage));
            if (!$mail->send()) {
                //   echo 'Mailer Error: ' . $mail->ErrorInfo;
                $newCustomerResult = '<span class="help-block text-danger"><div class="alert alert-danger">Sorry, there was an error sending your message. Please try again later.</div></span>';
            } else {
                $newCustomerResult = '<span class="help-block text-danger"><div class="alert alert-success">Thank you! We will be in touch.</div></span>';
            }
            $mail->Subject = 'Confirmation that Jantzen Enquiry Form was Submitted';
            $mail->ClearAllRecipients();
            //ref: http://stackoverflow.com/a/10952558/3553367
            if ($use == "household") {
                $mail->addAddress($email, $name);
            } else {
                $mail->addAddress($email, $companyName);
            }
            $mail->ClearReplyTos();
            //ref: http://stackoverflow.com/a/24864124/3553367
            $mail->addReplyTo($emailFrom, 'Jantzen');
            $htmlEmailIntro = '<h3 style="color: black;">Janten has received your enquiry as a new customer, below is the form submitted to us!<br>Emails should be sent to info@jantzen.com.my</h3>';
            $mail->MsgHTML(str_replace('<!--%htmlEmailIntro%-->', $htmlEmailIntro, $htmlMessage));
            $mail->send();
        } else {
            $newCustomerResult = '<span class="help-block text-danger"><div class="alert alert-danger">Please verify your inputs, failed validation check.</div></span>';
        }
    }
}
?>


<!DOCTYPE html>
<html lang="en">
Beispiel #18
0
/**
 * Returns a PHPMailer with everything set except the recipients
 *
 * $pMessage['subject'] - The subject
 * $pMessage['message'] - The HTML body of the message
 * $pMessage['alt_message'] - The Non HTML body of the message
 */
function transport_email_build_mailer($pMessage)
{
    global $gBitSystem, $gBitLanguage;
    require_once UTIL_PKG_PATH . 'phpmailer/class.phpmailer.php';
    $mailer = new PHPMailer();
    $mailer->From = !empty($pMessage['from']) ? $pMessage['from'] : $gBitSystem->getConfig('bitmailer_sender_email', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN']));
    $mailer->FromName = !empty($pMessage['from_name']) ? $pMessage['from_name'] : $gBitSystem->getConfig('bitmailer_from', $gBitSystem->getConfig('site_title'));
    if (!empty($pMessage['sender'])) {
        $mailer->Sender = $pMessage['sender'];
    }
    $mailer->Host = $gBitSystem->getConfig('bitmailer_servers', $gBitSystem->getConfig('kernel_server_name', '127.0.0.1'));
    $mailer->Mailer = $gBitSystem->getConfig('bitmailer_protocol', 'smtp');
    // Alternative to IsSMTP()
    $mailer->CharSet = 'UTF-8';
    if ($gBitSystem->getConfig('bitmailer_ssl') == 'y') {
        $mailer->SMTPSecurity = "ssl";
        // secure transfer enabled
        $mailer->Port = $gBitSystem->getConfig('bitmailer_port', '25');
    }
    if ($gBitSystem->getConfig('bitmailer_smtp_username')) {
        $mailer->SMTPAuth = TRUE;
        $mailer->Username = $gBitSystem->getConfig('bitmailer_smtp_username');
    }
    if ($gBitSystem->getConfig('bitmailer_smtp_password')) {
        $mailer->Password = $gBitSystem->getConfig('bitmailer_smtp_password');
    }
    $mailer->WordWrap = $gBitSystem->getConfig('bitmailer_word_wrap', 75);
    if (!$mailer->SetLanguage($gBitLanguage->getLanguage(), UTIL_PKG_PATH . 'phpmailer/language/')) {
        $mailer->SetLanguage('en');
    }
    if (!empty($pMessage['x_headers']) && is_array($pMessage['x_headers'])) {
        foreach ($pMessage['x_headers'] as $name => $value) {
            /* Not sure what this is intended to do
            			   but nothing seems to use it yet but boards
            			   that I am hacking on now. 29-11-08
            			   XOXO - Nick
            			if( !$mailer->set( $name, $value ) ) {
            				$mailer->$name = $value;
            				bit_error_log( $mailer->ErrorInfo );
            			}
            			*/
            $mailer->AddCustomHeader($name . ":" . $value);
        }
    }
    $mailer->ClearReplyTos();
    $mailer->AddReplyTo(!empty($pMessage['replyto']) ? $pMessage['replyto'] : $gBitSystem->getConfig('bitmailer_replyto_email', $gBitSystem->getConfig('bitmailer_sender_email')));
    if (empty($pMessage['subject'])) {
        $mailer->Subject = $gBitSystem->getConfig('site_title', '') . (empty($pMessage['package']) ? '' : " : " . $pMessage['package']) . (empty($pMessage['type']) ? '' : " : " . $pMessage['type']);
    } else {
        $mailer->Subject = $pMessage['subject'];
    }
    if (!empty($pMessage['message'])) {
        $mailer->Body = $pMessage['message'];
        $mailer->IsHTML(TRUE);
        if (!empty($pMessage['alt_message'])) {
            $mailer->AltBody = $pMessage['alt_message'];
        } else {
            $mailer->AltBody = '';
        }
    } elseif (!empty($pMessage['alt_message'])) {
        // although plain text, use Body so that clients reading html by default see the msg. header is correctly set as text/plain
        $mailer->Body = $pMessage['alt_message'];
        $mailer->IsHTML(FALSE);
    }
    return $mailer;
}
Beispiel #19
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * If $message is an array, the key of each is used to add as an attachment
  * with the value used as the body. The 'text/plain' element is used as the
  * text version of the body, with the 'text/html' element used as the HTML
  * version of the body. All other types are added as attachments.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *    phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @param string|array $to Array or comma-separated list of email addresses to send message.
  * @param string $subject Email subject
  * @param string|array $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @param string|array $attachments Optional. Files to attach.
  * @return bool Whether the email contents were sent successfully.
  */
 function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         $cc = array();
         $bcc = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 switch (strtolower($name)) {
                     // Mainly for legacy -- process a From: header if it's there
                     case 'from':
                         if (strpos($content, '<') !== false) {
                             // So... making my life hard again?
                             $from_name = substr($content, 0, strpos($content, '<') - 1);
                             $from_name = str_replace('"', '', $from_name);
                             $from_name = trim($from_name);
                             $from_email = substr($content, strpos($content, '<') + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                         } else {
                             $from_email = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (is_array($message)) {
                             // Multipart email, ignore the content-type header
                             break;
                         }
                         if (strpos($content, ';') !== false) {
                             list($type, $charset) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                             } elseif (false !== stripos($charset, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset));
                                 $charset = '';
                             }
                         } else {
                             $content_type = trim($content);
                         }
                         break;
                     case 'cc':
                         $cc = array_merge((array) $cc, explode(',', $content));
                         break;
                     case 'bcc':
                         $bcc = array_merge((array) $bcc, explode(',', $content));
                         break;
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* If we don't have an email from the input headers default to wordpress@$sitename
      * Some hosts will block outgoing mail from this address if it doesn't exist but
      * there's no easy alternative. Defaulting to admin_email might appear to be another
      * option but some hosts may refuse to relay mail from an unknown domain. See
      * http://trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     foreach ((array) $to as $recipient) {
         try {
             // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
             $recipient_name = '';
             if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                 if (count($matches) == 3) {
                     $recipient_name = $matches[1];
                     $recipient = $matches[2];
                 }
             }
             $phpmailer->AddAddress(trim($recipient), $recipient_name);
         } catch (phpmailerException $e) {
             continue;
         }
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = get_bloginfo('charset');
     }
     // Set the content-type and charset
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     if (is_string($message)) {
         $phpmailer->Body = $message;
         // Set Content-Type and charset
         // If we don't have a content-type from the input headers
         if (!isset($content_type)) {
             $content_type = 'text/plain';
         }
         $content_type = apply_filters('wp_mail_content_type', $content_type);
         $phpmailer->ContentType = $content_type;
         // Set whether it's plaintext, depending on $content_type
         if ('text/html' == $content_type) {
             $phpmailer->IsHTML(true);
         }
         // For backwards compatibility, new multipart emails should use
         // the array style $message. This never really worked well anyway
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     } elseif (is_array($message)) {
         foreach ($message as $type => $bodies) {
             foreach ((array) $bodies as $body) {
                 if ($type === 'text/html') {
                     $phpmailer->Body = $body;
                 } elseif ($type === 'text/plain') {
                     $phpmailer->AltBody = $body;
                 } else {
                     $phpmailer->AddAttachment($body, '', 'base64', $type);
                 }
             }
         }
     }
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddCc(trim($recipient), $recipient_name);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddBcc(trim($recipient), $recipient_name);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             try {
                 $phpmailer->AddAttachment($attachment);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     try {
         $phpmailer->Send();
     } catch (phpmailerException $e) {
         return false;
     }
     return true;
 }
Beispiel #20
0
/**
 * @param integer $action
 */
function send_mail($id_entry, $action, $dformat, $tab_id_moderes = array())
{
    global $vocab, $grrSettings, $locale, $weekstarts, $enable_periods, $periods_name;
    $message_erreur = '';
    // $action = 1 -> Création
    // $action = 2 -> Modification
    // $action = 3 -> Suppression
    // $action = 4 -> Suppression automatique
    // $action = 5 -> réservation en attente de modération
    // $action = 6 -> Résultat d'une décision de modération
    // $action = 7 -> Notification d'un retard dans la restitution d'une ressource.
    /* fixme faire le tri entre phpMailer et la class my_mailer */
    /* todo ajouter un $port smtp dans les settings */
    require_once 'phpmailer/PHPMailerAutoload.php';
    define('GRR_FROM', Settings::get('grr_mail_from'));
    define('GRR_FROMNAME', Settings::get('grr_mail_fromname'));
    require_once './include/mail.inc.php';
    //$m = new my_phpmailer();
    $mail = new PHPMailer();
    if (Settings::get('grr_mail_method') == 'smtp') {
        $smtpUsername = Settings::get('grr_mail_Username');
        $smtpPassword = Settings::get('grr_mail_Password');
        if ($smtpUsername != "") {
            $mail->SMTPAuth = true;
            $mail->Username = $smtpUsername;
            $mail->Password = $smtpPassword;
        } else {
            $mail->SMTPAuth = false;
        }
        $mail->Host = Settings::get('grr_mail_smtp');
        $mail->Port = 587;
        $mail->isSMTP();
    } else {
        $mail->isSendMail();
    }
    //$mail->SMTPDebug = 2;
    //$mail->Debugoutput = 'html';
    $mail->CharSet = 'UTF-8';
    $mail->setFrom(GRR_FROM, GRR_FROMNAME);
    $mail->SetLanguage("fr", "./phpmailer/language/");
    setlocale(LC_ALL, $locale);
    $sql = "SELECT " . TABLE_PREFIX . "_entry.name,\n\t" . TABLE_PREFIX . "_entry.description,\n\t" . TABLE_PREFIX . "_entry.beneficiaire,\n\t" . TABLE_PREFIX . "_room.room_name,\n\t" . TABLE_PREFIX . "_area.area_name,\n\t" . TABLE_PREFIX . "_entry.type,\n\t" . TABLE_PREFIX . "_entry.room_id,\n\t" . TABLE_PREFIX . "_entry.repeat_id,\n\t" . grr_sql_syntax_timestamp_to_unix("" . TABLE_PREFIX . "_entry.timestamp") . ",\n\t(" . TABLE_PREFIX . "_entry.end_time - " . TABLE_PREFIX . "_entry.start_time),\n\t" . TABLE_PREFIX . "_entry.start_time,\n\t" . TABLE_PREFIX . "_entry.end_time,\n\t" . TABLE_PREFIX . "_room.area_id,\n\t" . TABLE_PREFIX . "_room.delais_option_reservation,\n\t" . TABLE_PREFIX . "_entry.option_reservation,\n\t" . TABLE_PREFIX . "_entry.moderate,\n\t" . TABLE_PREFIX . "_entry.beneficiaire_ext,\n\t" . TABLE_PREFIX . "_entry.jours,\n\t" . TABLE_PREFIX . "_entry.clef,\n\t" . TABLE_PREFIX . "_entry.courrier\n\tFROM " . TABLE_PREFIX . "_entry, " . TABLE_PREFIX . "_room, " . TABLE_PREFIX . "_area\n\tWHERE " . TABLE_PREFIX . "_entry.room_id = " . TABLE_PREFIX . "_room.id\n\tAND " . TABLE_PREFIX . "_room.area_id = " . TABLE_PREFIX . "_area.id\n\tAND " . TABLE_PREFIX . "_entry.id='" . protect_data_sql($id_entry) . "'\n\t";
    $res = grr_sql_query($sql);
    if (!$res) {
        fatal_error(0, grr_sql_error());
    }
    if (grr_sql_count($res) < 1) {
        fatal_error(0, get_vocab('invalid_entry_id'));
    }
    $row = grr_sql_row($res, 0);
    grr_sql_free($res);
    get_planning_area_values($row[12]);
    $breve_description = bbcode(removeMailUnicode(htmlspecialchars($row[0])), 'nobbcode');
    $description = bbcode(removeMailUnicode(htmlspecialchars($row[1])), 'nobbcode');
    $beneficiaire = htmlspecialchars($row[2]);
    $room_name = removeMailUnicode(htmlspecialchars($row[3]));
    $area_name = removeMailUnicode(htmlspecialchars($row[4]));
    $room_id = $row[6];
    $repeat_id = $row[7];
    $date_avis = strftime("%Y/%m/%d", $row[10]);
    $delais_option_reservation = $row[13];
    $option_reservation = $row[14];
    $moderate = $row[15];
    $beneficiaire_ext = htmlspecialchars($row[16]);
    $jours_cycle = htmlspecialchars($row[17]);
    $duration = $row[9];
    if ($enable_periods == 'y') {
        list($start_period, $start_date) = period_date_string($row[10]);
    } else {
        $start_date = time_date_string($row[10], $dformat);
    }
    $rep_type = 0;
    if ($repeat_id != 0) {
        $res = grr_sql_query("SELECT rep_type, end_date, rep_opt, rep_num_weeks FROM " . TABLE_PREFIX . "_repeat WHERE id='" . protect_data_sql($repeat_id) . "'");
        if (!$res) {
            fatal_error(0, grr_sql_error());
        }
        $test = grr_sql_count($res);
        if ($test != 1) {
            fatal_error(0, "Deux reservation on le meme ID.");
        } else {
            $row2 = grr_sql_row($res, 0);
            $rep_type = $row2[0];
            $rep_end_date = strftime($dformat, $row2[1]);
            $rep_opt = $row2[2];
            $rep_num_weeks = $row2[3];
        }
        grr_sql_free($res);
    }
    if ($enable_periods == 'y') {
        toPeriodString($start_period, $duration, $dur_units);
    } else {
        toTimeString($duration, $dur_units);
    }
    $weeklist = array("unused", "every week", "week 1/2", "week 1/3", "week 1/4", "week 1/5");
    if ($rep_type == 2) {
        $affiche_period = $vocab[$weeklist[$rep_num_weeks]];
    } else {
        $affiche_period = $vocab['rep_type_' . $rep_type];
    }
    // Le bénéficiaire
    $beneficiaire_email = affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, "onlymail");
    if ($beneficiaire != "") {
        $beneficiaire_actif = grr_sql_query1("SELECT etat FROM " . TABLE_PREFIX . "_utilisateurs WHERE login='******'");
        if ($beneficiaire_actif == -1) {
            $beneficiaire_actif = 'actif';
        }
        // Cas des admins
    } else {
        if ($beneficiaire_ext != "" && $beneficiaire_email != "") {
            $beneficiaire_actif = "actif";
        } else {
            $beneficiaire_actif = "inactif";
        }
    }
    // Utilisateur ayant agit sur la réservation
    $user_login = getUserName();
    $user_email = grr_sql_query1("SELECT email FROM " . TABLE_PREFIX . "_utilisateurs WHERE login='******'");
    //
    // Elaboration du message destiné aux utilisateurs désignés par l'admin dans la partie "Mails automatiques"
    //
    //Nom de l'établissement et mention "mail automatique"
    $message = removeMailUnicode(Settings::get("company")) . " - " . $vocab["title_mail"];
    // Url de GRR
    $message = $message . traite_grr_url("", "y") . "\n\n";
    $sujet = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
    if ($action == 1) {
        $sujet = $sujet . $vocab["subject_mail_creation"];
        $message .= $vocab["the_user"] . affiche_nom_prenom_email($user_login, "", "formail");
        $message = $message . $vocab["creation_booking"];
        $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") \n";
    } else {
        if ($action == 2) {
            $sujet = $sujet . $vocab["subject_mail_modify"];
            if ($moderate == 1) {
                $sujet .= " (" . $vocab["en_attente_moderation"] . ")";
            }
            $message .= $vocab["the_user"] . affiche_nom_prenom_email($user_login, "", "formail");
            $message = $message . $vocab["modify_booking"];
            $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") ";
        } else {
            if ($action == 3) {
                $sujet = $sujet . $vocab["subject_mail_delete"];
                if ($moderate == 1) {
                    $sujet .= " (" . $vocab["en_attente_moderation"] . ")";
                }
                $message .= $vocab["the_user"] . affiche_nom_prenom_email($user_login, "", "formail");
                $message = $message . $vocab["delete_booking"];
                $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") \n";
            } else {
                if ($action == 4) {
                    $sujet = $sujet . $vocab["subject_mail_delete"];
                    $message = $message . $vocab["suppression_automatique"];
                    $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") \n";
                } else {
                    if ($action == 5) {
                        $sujet = $sujet . $vocab["subject_mail_moderation"];
                        $message = $message . $vocab["reservation_en_attente_de_moderation"];
                        $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") \n";
                    } else {
                        if ($action == 6) {
                            $sujet = $sujet . $vocab["subject_mail_decision_moderation"];
                            $resmoderate = grr_sql_query("SELECT moderate, motivation_moderation FROM " . TABLE_PREFIX . "_entry_moderate WHERE id ='" . protect_data_sql($id_entry) . "'");
                            if (!$resmoderate) {
                                fatal_error(0, grr_sql_error());
                            }
                            if (grr_sql_count($resmoderate) < 1) {
                                fatal_error(0, get_vocab('invalid_entry_id'));
                            }
                            $rowModerate = grr_sql_row($resmoderate, 0);
                            grr_sql_free($resmoderate);
                            $moderate_decision = $rowModerate[0];
                            $moderate_description = $rowModerate[1];
                            $message .= $vocab["the_user"] . affiche_nom_prenom_email($user_login, "", "formail");
                            $message = $message . $vocab["traite_moderation"];
                            $message = $message . $vocab["the_room"] . $room_name . " (" . $area_name . ") ";
                            $message = $message . $vocab["reservee au nom de"];
                            $message = $message . $vocab["the_user"] . affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, "formail") . " \n";
                            if ($moderate_decision == 2) {
                                $message .= "\n" . $vocab["moderation_acceptee"];
                            } else {
                                if ($moderate_decision == 3) {
                                    $message .= "\n" . $vocab["moderation_refusee"];
                                }
                            }
                            if ($moderate_description != "") {
                                $message .= "\n" . $vocab["motif"] . $vocab["deux_points"];
                                $message .= $moderate_description . " \n----";
                            }
                            $message .= "\n" . $vocab["voir_details"] . $vocab["deux_points"] . "\n";
                            if (count($tab_id_moderes) == 0) {
                                $message .= "\n" . traite_grr_url("", "y") . "view_entry.php?id=" . $id_entry;
                            } else {
                                foreach ($tab_id_moderes as $id_moderes) {
                                    $message .= "\n" . traite_grr_url("", "y") . "view_entry.php?id=" . $id_moderes;
                                }
                            }
                            $message .= "\n\n" . $vocab["rappel_de_la_demande"] . $vocab["deux_points"] . "\n";
                        } else {
                            if ($action == 7) {
                                $sujet .= $vocab["subject_mail_retard"];
                                $message .= $vocab["message_mail_retard"] . $vocab["deux_points"] . " \n";
                                $message .= $room_name . " (" . $area_name . ") \n";
                                $message .= $vocab["nom emprunteur"] . $vocab["deux_points"];
                                $message .= affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, "formail") . " \n";
                                if ($beneficiaire_email != "") {
                                    $message .= $vocab["un email envoye"] . $beneficiaire_email . " \n";
                                }
                                $message .= "\n" . $vocab["changer statut lorsque ressource restituee"] . $vocab["deux_points"];
                                $message .= "\n" . traite_grr_url("", "y") . "view_entry.php?id=" . $id_entry . " \n";
                            }
                        }
                    }
                }
            }
        }
    }
    if ($action == 2 || $action == 3) {
        $message = $message . $vocab["reservee au nom de"];
        $message = $message . $vocab["the_user"] . affiche_nom_prenom_email($beneficiaire, $beneficiaire_ext, "formail") . " \n";
    }
    if ($action == 5 || $action == 7) {
        $repondre = Settings::get("webmaster_email");
    } else {
        $repondre = $user_email;
    }
    //
    // Infos sur la réservation
    //
    $reservation = '';
    $reservation = $reservation . $vocab["start_of_the_booking"] . " " . $start_date . "\n";
    $reservation = $reservation . $vocab["duration"] . " " . $duration . " " . $dur_units . "\n";
    if (trim($breve_description) != "") {
        $reservation = $reservation . $vocab["namebooker"] . preg_replace("/ /", " ", $vocab["deux_points"]) . " " . $breve_description . "\n";
    } else {
        $reservation = $reservation . $vocab["entryid"] . $room_id . "\n";
    }
    if ($description != '') {
        $reservation = $reservation . $vocab["description"] . " " . $description . "\n";
    }
    // Champ additionnel
    $reservation .= affichage_champ_add_mails($id_entry);
    // Type de réservation
    $temp = grr_sql_query1("SELECT type_name FROM " . TABLE_PREFIX . "_type_area WHERE type_letter='" . $row[5] . "'");
    if ($temp == -1) {
        $temp = "?" . $row[5] . "?";
    } else {
        $temp = removeMailUnicode($temp);
    }
    $reservation = $reservation . $vocab["type"] . preg_replace("/ /", " ", $vocab["deux_points"]) . " " . $temp . "\n";
    if ($rep_type != 0) {
        $reservation = $reservation . $vocab["rep_type"] . " " . $affiche_period . "\n";
    }
    if ($rep_type != 0) {
        if ($rep_type == 2) {
            $opt = "";
            for ($i = 0; $i < 7; $i++) {
                $daynum = ($i + $weekstarts) % 7;
                if ($rep_opt[$daynum]) {
                    $opt .= day_name($daynum) . " ";
                }
            }
            if ($opt) {
                $reservation = $reservation . $vocab["rep_rep_day"] . " " . $opt . "\n";
            }
        }
        if ($rep_type == 6) {
            if (Settings::get("jours_cycles_actif") == "Oui") {
                $reservation = $reservation . $vocab["rep_type_6"] . preg_replace("/ /", " ", $vocab["deux_points"]) . ucfirst(substr($vocab["rep_type_6"], 0, 1)) . $jours_cycle . "\n";
            }
        }
        $reservation = $reservation . $vocab["rep_end_date"] . " " . $rep_end_date . "\n";
    }
    if ($delais_option_reservation > 0 && $option_reservation != -1) {
        $reservation = $reservation . "*** " . $vocab["reservation_a_confirmer_au_plus_tard_le"] . " " . time_date_string_jma($option_reservation, $dformat) . " ***\n";
    }
    $reservation = $reservation . "-----\n";
    $message = $message . $reservation;
    $message = $message . $vocab["msg_no_email"] . Settings::get("webmaster_email");
    $message = html_entity_decode($message);
    $sql = "SELECT u.email FROM " . TABLE_PREFIX . "_utilisateurs u, " . TABLE_PREFIX . "_j_mailuser_room j WHERE (j.id_room='" . protect_data_sql($room_id) . "' AND u.login=j.login and u.etat='actif') ORDER BY u.nom, u.prenom";
    $res = grr_sql_query($sql);
    $nombre = grr_sql_count($res);
    if ($nombre > 0) {
        $tab_destinataire = array();
        for ($i = 0; $row = grr_sql_row($res, $i); $i++) {
            if ($row[0] != "") {
                $tab_destinataire[] = $row[0];
            }
        }
        foreach ($tab_destinataire as $value) {
            if (Settings::get("grr_mail_Bcc") == "y") {
                $mail->AddBCC($value);
            } else {
                $mail->AddAddress($value);
            }
        }
        $mail->Subject = $sujet;
        $mail->Body = $message;
        $mail->AddReplyTo($repondre);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
    }
    $mail->ClearAddresses();
    $mail->ClearBCCs();
    $mail->ClearReplyTos();
    if ($action == 7) {
        $mail_admin = find_user_room($room_id);
        if (count($mail_admin) > 0) {
            foreach ($mail_admin as $value) {
                if (Settings::get("grr_mail_Bcc") == "y") {
                    $mail->AddBCC($value);
                } else {
                    $mail->AddAddress($value);
                }
            }
            $mail->Subject = $sujet;
            $mail->Body = $message;
            $mail->AddReplyTo($repondre);
            if (!$mail->Send()) {
                $message_erreur .= $mail->ErrorInfo;
            }
        }
        $mail->ClearAddresses();
        $mail->ClearBCCs();
        $mail->ClearReplyTos();
    }
    if ($action == 7) {
        $sujet7 = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
        $sujet7 .= $vocab["subject_mail_retard"];
        $message7 = removeMailUnicode(Settings::get("company")) . " - " . $vocab["title_mail"];
        $message7 .= traite_grr_url("", "y") . "\n\n";
        $message7 .= $vocab["ressource empruntee non restituée"] . "\n";
        $message7 .= $room_name . " (" . $area_name . ")";
        $message7 .= "\n" . $reservation;
        $message7 = html_entity_decode($message7);
        $destinataire7 = $beneficiaire_email;
        $repondre7 = Settings::get("webmaster_email");
        $mail->AddAddress($destinataire7);
        $mail->Subject = $sujet7;
        $mail->Body = $message7;
        $mail->AddReplyTo($repondre7);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 4) {
        $destinataire4 = $beneficiaire_email;
        $repondre4 = Settings::get("webmaster_email");
        $mail->AddAddress($destinataire4);
        $mail->Subject = $sujet;
        $mail->Body = $message;
        $mail->AddReplyTo($repondre4);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 5) {
        $mail_admin = find_user_room($room_id);
        if (count($mail_admin) > 0) {
            foreach ($mail_admin as $value) {
                if (Settings::get("grr_mail_Bcc") == "y") {
                    $mail->AddBCC($value);
                } else {
                    $mail->AddAddress($value);
                }
            }
            $sujet5 = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
            $sujet5 .= $vocab["subject_mail_moderation"];
            $message5 = removeMailUnicode(Settings::get("company")) . " - " . $vocab["title_mail"];
            $message5 .= traite_grr_url("", "y") . "\n\n";
            $message5 .= $vocab["subject_a_moderer"];
            $message5 .= "\n" . traite_grr_url("", "y") . "validation.php?id=" . $id_entry;
            $message5 .= "\n\n" . $vocab['created_by'] . affiche_nom_prenom_email($user_login, "", "formail");
            $message5 .= "\n" . $vocab['room'] . $vocab['deux_points'] . $room_name . " (" . $area_name . ") \n";
            $message5 = html_entity_decode($message5);
            $repondre5 = Settings::get("webmaster_email");
            $mail->Subject = $sujet5;
            $mail->Body = $message5;
            $mail->AddReplyTo($repondre5);
            if (!$mail->Send()) {
                $message_erreur .= $mail->ErrorInfo;
            }
        }
        $mail->ClearAddresses();
        $mail->ClearBCCs();
        $mail->ClearReplyTos();
    }
    if ($action == 5 && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet5 = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
        $sujet5 .= $vocab["subject_mail_moderation"];
        $message5 = removeMailUnicode(Settings::get("company")) . " - " . $vocab["title_mail"];
        $message5 .= traite_grr_url("", "y") . "\n\n";
        $message5 .= $vocab["texte_en_attente_de_moderation"];
        $message5 .= "\n" . $vocab["rappel_de_la_demande"] . $vocab["deux_points"];
        $message5 .= "\n" . $vocab["the_room"] . $room_name . " (" . $area_name . ")";
        $message5 .= "\n" . $reservation;
        $message5 = html_entity_decode($message5);
        $destinataire5 = $beneficiaire_email;
        $repondre5 = Settings::get("webmaster_email");
        $mail->AddAddress($destinataire5);
        $mail->Subject = $sujet5;
        $mail->Body = $message5;
        $mail->AddReplyTo($repondre5);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    if ($action == 6 && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet6 = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
        $sujet6 .= $vocab["subject_mail_decision_moderation"];
        $message6 = $message;
        $destinataire6 = $beneficiaire_email;
        $repondre6 = $user_email;
        $mail->AddAddress($destinataire6);
        $mail->Subject = $sujet6;
        $mail->Body = $message6;
        $mail->AddReplyTo($repondre6);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    // Cas d'une création, modification ou suppression d'un message par un utilisateur différent du bénéficiaire :
    // On envoie un message au bénéficiaire de la réservation pour l'avertir d'une modif ou d'une suppression
    if (($action == 1 || $action == 2 || $action == 3) && (strtolower($user_login) != strtolower($beneficiaire) || Settings::get('send_always_mail_to_creator') == '1') && $beneficiaire_email != '' && $beneficiaire_actif == 'actif') {
        $sujet2 = $vocab["subject_mail1"] . $room_name . " - " . $date_avis;
        $message2 = removeMailUnicode(Settings::get("company")) . " - " . $vocab["title_mail"];
        $message2 = $message2 . traite_grr_url("", "y") . "\n\n";
        $message2 = $message2 . $vocab["the_user"] . affiche_nom_prenom_email($user_login, "", "formail");
        if ($action == 1) {
            $sujet2 = $sujet2 . $vocab["subject_mail_creation"];
            $message2 = $message2 . $vocab["creation_booking_for_you"];
            $message2 = $message2 . $vocab["the_room"] . $room_name . " (" . $area_name . ").";
        } else {
            if ($action == 2) {
                $sujet2 = $sujet2 . $vocab["subject_mail_modify"];
                $message2 = $message2 . $vocab["modify_booking"];
                $message2 = $message2 . $vocab["the_room"] . $room_name . " (" . $area_name . ")";
                $message2 = $message2 . $vocab["created_by_you"];
            } else {
                $sujet2 = $sujet2 . $vocab["subject_mail_delete"];
                $message2 = $message2 . $vocab["delete_booking"];
                $message2 = $message2 . $vocab["the_room"] . $room_name . " (" . $area_name . ")";
                $message2 = $message2 . $vocab["created_by_you"];
            }
        }
        $message2 = $message2 . "\n" . $reservation;
        $message2 = html_entity_decode($message2);
        $destinataire2 = $beneficiaire_email;
        $repondre2 = $user_email;
        $mail->AddAddress($destinataire2);
        $mail->Subject = $sujet2;
        $mail->Body = $message2;
        $mail->AddReplyTo($repondre2);
        if (!$mail->Send()) {
            $message_erreur .= $mail->ErrorInfo;
        }
        $mail->ClearAddresses();
        $mail->ClearReplyTos();
    }
    return $message_erreur;
}
Beispiel #21
0
function rsvpmailer($mail)
{
    global $rsvp_options;
    require_once ABSPATH . WPINC . '/class-phpmailer.php';
    require_once ABSPATH . WPINC . '/class-smtp.php';
    $rsvpmail = new PHPMailer();
    $rsvpmail->IsSMTP();
    // telling the class to use SMTP
    if ($rsvp_options["smtp"] == "gmail") {
        $rsvpmail->SMTPAuth = true;
        // enable SMTP authentication
        $rsvpmail->SMTPSecure = "tls";
        // sets the prefix to the servier
        $rsvpmail->Host = "smtp.gmail.com";
        // sets GMAIL as the SMTP server
        $rsvpmail->Port = 587;
        // set the SMTP port for the GMAIL server
    } elseif ($rsvp_options["smtp"] == "sendgrid") {
        $rsvpmail->SMTPAuth = true;
        // enable SMTP authentication
        $rsvpmail->SMTPSecure = "tls";
        // sets the prefix to the servier
        $rsvpmail->Host = 'smtp.sendgrid.net';
        $rsvpmail->Port = 587;
    } else {
        $rsvpmail->Host = $rsvp_options["smtp_server"];
        // SMTP server
        $rsvpmail->SMTPAuth = true;
        if (isset($rsvp_options["smtp_prefix"]) && $rsvp_options["smtp_prefix"]) {
            $rsvpmail->SMTPSecure = $rsvp_options["smtp_prefix"];
        }
        // sets the prefix to the servier
        $rsvpmail->Port = $rsvp_options["smtp_port"];
    }
    if ($_GET["debug"]) {
        printf('<p>Auth: %s<br />
Secure: %s<br />
Host: %s<br />
Port: %s<br />
RSVP SMTP: %s<br />
</p>', $rsvpmail->SMTPAuth, $rsvpmail->SMTPSecure, $rsvpmail->Host, $rsvpmail->Port, $rsvp_options["smtp"]);
    }
    $rsvpmail->Username = $rsvp_options["smtp_username"];
    $rsvpmail->Password = $rsvp_options["smtp_password"];
    $rsvpmail->AddAddress($mail["to"]);
    if (isset($mail["cc"])) {
        $rsvpmail->AddCC($mail["cc"]);
    }
    if (is_admin() && isset($_GET["debug"])) {
        $rsvpmail->SMTPDebug = 2;
    }
    $rsvpmail->SetFrom($rsvp_options["smtp_useremail"], $mail["fromname"] . ' (via ' . $_SERVER['SERVER_NAME'] . ')');
    $rsvpmail->ClearReplyTos();
    $rsvpmail->AddReplyTo($mail["from"], $mail["fromname"]);
    $rsvpmail->Subject = $mail["subject"];
    if ($mail["html"]) {
        if ($mail["text"]) {
            $rsvpmail->AltBody = $mail["text"];
        } else {
            $rsvpmail->AltBody = trim(strip_tags($mail["html"]));
        }
        $rsvpmail->MsgHTML($mail["html"]);
    } else {
        $rsvpmail->Body = $mail["text"];
        $rsvpmail->WordWrap = 50;
    }
    try {
        $rsvpmail->Send();
    } catch (phpmailerException $e) {
        echo $e->errorMessage();
    } catch (Exception $e) {
        echo $e->getMessage();
        //Boring error messages from anything else!
    }
    return $rsvpmail->ErrorInfo;
}
Beispiel #22
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @param string $to Email address to send message
  * @param string $subject Email subject
  * @param string $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @return bool Whether the email contents were sent successfully.
  */
 function wp_mail($to, $subject, $message, $headers = '')
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers')));
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer();
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } elseif (!is_array($headers)) {
         // Explode the headers out, so this function can take both
         // string headers and an array of headers.
         $tempheaders = (array) explode("\n", $headers);
         $headers = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ($tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 // Mainly for legacy -- process a From: header if it's there
                 if ('from' == strtolower($name)) {
                     if (strpos($content, '<') !== false) {
                         // So... making my life hard again?
                         $from_name = substr($content, 0, strpos($content, '<') - 1);
                         $from_name = str_replace('"', '', $from_name);
                         $from_name = trim($from_name);
                         $from_email = substr($content, strpos($content, '<') + 1);
                         $from_email = str_replace('>', '', $from_email);
                         $from_email = trim($from_email);
                     } else {
                         $from_name = trim($content);
                     }
                 } elseif ('content-type' == strtolower($name)) {
                     if (strpos($content, ';') !== false) {
                         list($type, $charset) = explode(';', $content);
                         $content_type = trim($type);
                         $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                     } else {
                         $content_type = trim($content);
                     }
                 } elseif ('cc' == strtolower($name)) {
                     $cc = explode(",", $content);
                 } elseif ('bcc' == strtolower($name)) {
                     $bcc = explode(",", $content);
                 } else {
                     // Add it to our grand headers array
                     $headers[trim($name)] = trim($content);
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     // If we don't have an email from the input headers
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Set the from name and email
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination address
     $phpmailer->AddAddress($to);
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ($cc as $recipient) {
             $phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ($bcc as $recipient) {
             $phpmailer->AddBcc(trim($recipient));
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/plain';
     }
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     // Set whether it's plaintext or not, depending on $content_type
     if ($content_type == 'text/html') {
         $phpmailer->IsHTML(true);
     } else {
         $phpmailer->IsHTML(false);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = get_bloginfo('charset');
     }
     // Set the content-type and charset
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ($headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     $result = @$phpmailer->Send();
     return $result;
 }
function wp_mail($to, $subject, $message, $headers = '') {
	global $phpmailer;

	if ( !is_object( $phpmailer ) ) {
		require_once(ABSPATH . WPINC . '/class-phpmailer.php');
		require_once(ABSPATH . WPINC . '/class-smtp.php');
		$phpmailer = new PHPMailer();
	}

	$mail = compact('to', 'subject', 'message', 'headers');
	$mail = apply_filters('wp_mail', $mail);
	extract($mail);

	if ( $headers == '' ) {
		$headers = "MIME-Version: 1.0\n" .
			"From: " . apply_filters('wp_mail_from', "wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']))) . "\n" . 
			"Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
	}

	$phpmailer->ClearAddresses();
	$phpmailer->ClearCCs();
	$phpmailer->ClearBCCs();
	$phpmailer->ClearReplyTos();
	$phpmailer->ClearAllRecipients();
	$phpmailer->ClearCustomHeaders();

	$phpmailer->FromName = "WordPress";
	$phpmailer->AddAddress("$to", "");
	$phpmailer->Subject = $subject;
	$phpmailer->Body    = $message;
	$phpmailer->IsHTML(false);
	$phpmailer->IsMail(); // set mailer to use php mail()

	do_action_ref_array('phpmailer_init', array(&$phpmailer));

	$mailheaders = (array) explode( "\n", $headers );
	foreach ( $mailheaders as $line ) {
		$header = explode( ":", $line );
		switch ( trim( $header[0] ) ) {
			case "From":
				$from = trim( str_replace( '"', '', $header[1] ) );
				if ( strpos( $from, '<' ) ) {
					$phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) );
					$from = trim( substr( $from, strpos( $from, '<' ) + 1 ) );
					$from = str_replace( '>', '', $from );
				} else {
					$phpmailer->FromName = $from;
				}
				$phpmailer->From = trim( $from );
				break;
			default:
				if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' )
					$phpmailer->AddCustomHeader( $line );
				break;
		}
	}

	$result = @$phpmailer->Send();

	return $result;
}
Beispiel #24
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  *
  * @uses PHPMailer
  *
  * @param string|array $to Array or comma-separated list of email addresses to send message.
  * @param string $subject Email subject
  * @param string $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @param string|array $attachments Optional. Files to attach.
  * @return bool Whether the email contents were sent successfully.
  */
 function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     /**
      * Filter the wp_mail() arguments.
      *
      * @since 2.2.0
      *
      * @param array $args A compacted array of wp_mail() arguments, including the "to" email,
      *                    subject, message, headers, and attachments values.
      */
     $atts = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'));
     if (isset($atts['to'])) {
         $to = $atts['to'];
     }
     if (isset($atts['subject'])) {
         $subject = $atts['subject'];
     }
     if (isset($atts['message'])) {
         $message = $atts['message'];
     }
     if (isset($atts['headers'])) {
         $headers = $atts['headers'];
     }
     if (isset($atts['attachments'])) {
         $attachments = $atts['attachments'];
     }
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!$phpmailer instanceof PHPMailer) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         $cc = array();
         $bcc = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 switch (strtolower($name)) {
                     // Mainly for legacy -- process a From: header if it's there
                     case 'from':
                         $bracket_pos = strpos($content, '<');
                         if ($bracket_pos !== false) {
                             // Text before the bracketed email is the "From" name.
                             if ($bracket_pos > 0) {
                                 $from_name = substr($content, 0, $bracket_pos - 1);
                                 $from_name = str_replace('"', '', $from_name);
                                 $from_name = trim($from_name);
                             }
                             $from_email = substr($content, $bracket_pos + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                             // Avoid setting an empty $from_email.
                         } elseif ('' !== trim($content)) {
                             $from_email = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (strpos($content, ';') !== false) {
                             list($type, $charset_content) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset_content, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset_content));
                             } elseif (false !== stripos($charset_content, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content));
                                 $charset = '';
                             }
                             // Avoid setting an empty $content_type.
                         } elseif ('' !== trim($content)) {
                             $content_type = trim($content);
                         }
                         break;
                     case 'cc':
                         $cc = array_merge((array) $cc, explode(',', $content));
                         break;
                     case 'bcc':
                         $bcc = array_merge((array) $bcc, explode(',', $content));
                         break;
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* If we don't have an email from the input headers default to wordpress@$sitename
      * Some hosts will block outgoing mail from this address if it doesn't exist but
      * there's no easy alternative. Defaulting to admin_email might appear to be another
      * option but some hosts may refuse to relay mail from an unknown domain. See
      * https://core.trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     /**
      * Filter the email address to send from.
      *
      * @since 2.2.0
      *
      * @param string $from_email Email address to send from.
      */
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     /**
      * Filter the name to associate with the "from" email address.
      *
      * @since 2.3.0
      *
      * @param string $from_name Name associated with the "from" email address.
      */
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     foreach ((array) $to as $recipient) {
         try {
             // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
             $recipient_name = '';
             if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                 if (count($matches) == 3) {
                     $recipient_name = $matches[1];
                     $recipient = $matches[2];
                 }
             }
             $phpmailer->AddAddress($recipient, $recipient_name);
         } catch (phpmailerException $e) {
             continue;
         }
     }
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddCc($recipient, $recipient_name);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddBcc($recipient, $recipient_name);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/plain';
     }
     /**
      * Filter the wp_mail() content type.
      *
      * @since 2.3.0
      *
      * @param string $content_type Default wp_mail() content type.
      */
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     $phpmailer->ContentType = $content_type;
     // Set whether it's plaintext, depending on $content_type
     if ('text/html' == $content_type) {
         $phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = get_bloginfo('charset');
     }
     // Set the content-type and charset
     /**
      * Filter the default wp_mail() charset.
      *
      * @since 2.3.0
      *
      * @param string $charset Default email charset.
      */
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             try {
                 $phpmailer->AddAttachment($attachment);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     /**
      * Fires after PHPMailer is initialized.
      *
      * @since 2.2.0
      *
      * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
      */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     try {
         return $phpmailer->Send();
     } catch (phpmailerException $e) {
         return false;
     }
 }
Beispiel #25
0
/**
 * Retrieve get PHPMailer object
 * @return PHPMailer
 */
function dhvc_form_phpmailer()
{
    if (!class_exists('PHPMailer')) {
        require_once ABSPATH . WPINC . '/class-phpmailer.php';
        require_once ABSPATH . WPINC . '/class-smtp.php';
    }
    $mailer = new PHPMailer(true);
    $mailer->ClearAllRecipients();
    $mailer->ClearAttachments();
    $mailer->ClearCustomHeaders();
    $mailer->ClearReplyTos();
    $mailer->IsMail();
    //$mailer->Mailer = 'mail';
    $mailer->CharSet = get_bloginfo('charset');
    if (dhvc_form_get_option('email_method', 'default') == 'smtp') {
        $mailer->IsSMTP();
        $smtp_host = dhvc_form_get_option('smtp_host');
        $smtp_post = dhvc_form_get_option('smtp_post');
        $smtp_username = dhvc_form_get_option('smtp_username');
        $smtp_password = dhvc_form_get_option('smtp_password');
        $smtp_encryption = dhvc_form_get_option('smtp_encryption');
        if (!empty($smtp_host)) {
            $mailer->Host = $smtp_host;
        }
        if (!empty($smtp_post)) {
            $mailer->Port = $smtp_post;
        }
        if (!empty($smtp_username) && !empty($smtp_password)) {
            $mailer->SMTPAuth = true;
            $mailer->Username = $smtp_username;
            $mailer->Password = $smtp_password;
        }
        if (in_array($smtp_encryption, array('tls', 'ssl'))) {
            $mailer->SMTPSecure = $smtp_encryption;
        }
    }
    return $mailer;
}
Beispiel #26
0
 $mail->SetFrom(Local::$from_email, Local::$from_name);
 $mail->CharSet = "UTF-8";
 $mail->Subject = 'Livraison de fichiers';
 $mail->Body = "Livraison du travail pour : " . $obj->titre . "\n\n" . "Votre commentaire :\n" . $_POST["commentaire"] . "\n\n" . "Les fichiers suivants ont ete recus :\n";
 //$mail->MsgHTML($mail->AltBody);
 // E-mail de notification (enseignant)
 $notifmail = new PHPMailer(true);
 // the true param means it will throw exceptions on errors, which we need to catch
 $notifmail->IsSMTP();
 // telling the class to use SMTP
 $notifmail->Host = Local::$smtp_relay;
 // SMTP server
 $notifmail->SMTPDebug = 0;
 // enables SMTP debug information (for testing)
 $notifmail->SetFrom(Local::$from_email, Local::$from_name);
 $notifmail->ClearReplyTos();
 $notifmail->CharSet = "UTF-8";
 // Fin préparation e-mail
 // traitement participants
 for ($i = 1; $i <= 3; $i++) {
     if (isset($_POST["nom" . $i]) && trim($_POST["nom" . $i]) != "" && trim($_POST["email" . $i]) != "") {
         // Ajout à l'e-mail
         $email = $_POST["email" . $i];
         echo "<!-- ";
         try {
             $mail->AddAddress($email, $email);
             $notifmail->AddReplyTo($email, trim($_POST["prenom" . $i]) . " " . trim($_POST["nom" . $i]));
             echo " -->";
             echo "<p>Destinataire de l'e-mail de confirmation : {$email}</p>";
         } catch (phpmailerException $e) {
             echo " -->";
Beispiel #27
0
 /**
  * Send mail for a particular $comment
  * Inspired by code from the core for wp_mail function.
  * 
  * @global PHPMailer $phpmailer
  * @param object $comment result of get_comment
  * @return boolean TRUE if all messages sent okay, FALSE if any individual send gives error.
  */
 public function send($comment)
 {
     global $phpmailer;
     // get PHPMailer and SMTP classes, if not already available.
     if (!is_object($phpmailer) || !is_a($phpmailer, "PHPMailer")) {
         require_once ABSPATH . WPINC . "/class-phpmailer.php";
         require_once ABSPATH . WPINC . "/class-smtp.php";
         $phpmailer = new PHPMailer(TRUE);
     }
     $num_messages = $this->numMessages();
     // send each message that has been loaded into this object:
     for ($mid = 0; $mid < $num_messages; $mid++) {
         $this->selectMessage($mid);
         $recipient_email = $comment->comment_author_email;
         $from_name = $this->getParsedFromName($comment);
         $from_email = $this->getParsedFromEmail($comment);
         $recipient_name = $comment->comment_author;
         $body_html = $this->getParsedHtmlMessage($comment);
         $body_plain = $this->getParsedPlainMessage($comment);
         // clear any previous PHPMailer settings
         $phpmailer->ClearAddresses();
         $phpmailer->ClearAllRecipients();
         $phpmailer->ClearAttachments();
         $phpmailer->ClearBCCs();
         $phpmailer->ClearCCs();
         $phpmailer->ClearCustomHeaders();
         $phpmailer->ClearReplyTos();
         // set from and subject
         $phpmailer->From = $from_email;
         $phpmailer->FromName = $from_name;
         $phpmailer->Subject = $this->getParsedSubject($comment);
         // set recipient
         try {
             if (version_compare(PHP_VERSION, "5.2.11", ">=") && version_compare(PHP_VERSION, "5.3", "<") || version_compare(PHP_VERSION, "5.3.1", ">=")) {
                 $phpmailer->AddAddress($recipient_email, $recipient_name);
             } else {
                 // Support: PHP <5.2.11 and PHP 3.0. mail() function on
                 // Windows has bug; doesn't deal with recipient name
                 // correctly. See https://bugs.php.net/bug.php?id=28038
                 $phpmailer->AddAddress(trim($recipient_email));
             }
         } catch (phpmailerException $e) {
             return FALSE;
         }
         // body HTML needs to be cut off at reasonable line length
         $body_html_wrapped = wordwrap($body_html, 900, "\n", TRUE);
         // add HTML body and alternative plain text.
         $phpmailer->Body = $body_html_wrapped;
         $phpmailer->isHTML(true);
         $phpmailer->AltBody = $body_plain;
         $phpmailer->Encoding = "8bit";
         $phpmailer->WordWrap = 80;
         // word wrap the plain text message
         $phpmailer->CharSet = "UTF-8";
         // try to send
         try {
             $phpmailer->Send();
         } catch (phpmailerException $e) {
             var_dump($e);
             return FALSE;
         }
         try {
         } catch (Exception $ex) {
         }
     }
     return TRUE;
 }