- if (Env::v('submit') == 'Envoyer')
- {
- $to2 = join(', ', Env::v('contacts', Array()));
- $txt = str_replace('^M', '', Env::v('contenu'));
- $to = Env::v('to');
- $subj = Env::v('sujet');
- $from = Env::v('from');
- $cc = Env::v('cc');
- $bcc = Env::v('bcc');
-
- if (empty($to) && empty($cc) && empty($to2)) {
- $page->trig("Indique au moins un destinataire.");
- } else {
- require_once("diogenes/diogenes.hermes.inc.php");
-
- $mymail = new HermesMailer();
- $mymail->setFrom($from);
- $mymail->setSubject($subj);
- if (!empty($to)) { $mymail->addTo($to); }
- if (!empty($cc)) { $mymail->addCc($cc); }
- if (!empty($bcc)) { $mymail->addBcc($bcc); }
- if (!empty($to2)) { $mymail->addTo($to2); }
- $mymail->addHeader('X-XOrg-Login', S::v('bestalias') . '@' . $globals->mail->domain);
- $mymail->setTxtBody(wordwrap($txt,72,"\n"));
- if ($mymail->send()) {
- $page->trig("Ton mail a bien été envoyé.");
- $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
+ if (Post::has('save')) {
+ unset($_POST['save']);
+ if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") {
+ $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
+ $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
+ $data = serialize($_POST);
+ XDB::execute("REPLACE INTO email_send_save
+ VALUES ({?}, {?})", S::i('uid'), $data);
+ }
+ exit;
+ } else if (Env::v('submit') == 'Envoyer') {
+ function getEmails($aliases)
+ {
+ if (!is_array($aliases)) {
+ return null;
+ }
+ $rel = Env::v('contacts');
+ $ret = array();
+ foreach ($aliases as $alias) {
+ $ret[$alias] = $rel[$alias];
+ }
+ return join(', ', $ret);
+ }
+
+ $error = false;
+ foreach ($_FILES as &$file) {
+ if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) {
+ $page->trig(PlUpload::$lastError);
+ $error = true;
+ break;
+ }
+ }
+
+ if (!$error) {
+ XDB::execute("DELETE FROM email_send_save
+ WHERE uid = {?}", S::i('uid'));
+
+ $to2 = getEmails(Env::v('to_contacts'));
+ $cc2 = getEmails(Env::v('cc_contacts'));
+ $txt = str_replace('^M', '', Env::v('contenu'));
+ $to = Env::v('to');
+ $subj = Env::v('sujet');
+ $from = Env::v('from');
+ $cc = trim(Env::v('cc'));
+ $bcc = trim(Env::v('bcc'));
+
+ if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
+ $page->trig("Indique au moins un destinataire.");
+ $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));