88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
require_once 'log.php';
|
|
require_once 'fonctions.inc.php';
|
|
|
|
|
|
function courrielEnvoi( $db )
|
|
{
|
|
$dicoExpe = getLang( $db->expeLang );
|
|
$dicoDest = getLang( $db->destLang );
|
|
$expediteurIndex = "Notification_denvoi_Expediteur";
|
|
//print "envoi du courriel" . EOL;
|
|
|
|
// Message à l'expéditeur
|
|
$indexObjet = "Objet_" . $expediteurIndex;
|
|
$result = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
|
|
log_write("indexObjet" .EOLH . print_r($result, true));
|
|
$objetMail = $result['text'];
|
|
$result = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) ;
|
|
log_write("indexObjet" .EOLH . print_r($result, true));
|
|
$mailText = $result['text'];
|
|
$html = $result['html'];
|
|
if ( $html )
|
|
{
|
|
$mailText = "<html><head></head>\n<body>" . $mailText . "</body></html>";
|
|
}
|
|
if ( $db->expeKnown == false )
|
|
{
|
|
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
|
|
}else
|
|
{
|
|
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
|
|
}
|
|
saveMail( $db, $db->expeMail, $objetMail, $mailText, $html);
|
|
|
|
// message au destinataire
|
|
$indexObjet = "Objet_" . $destinataireIndex;
|
|
$result = replaceVariables($db, $dicoDest[$indexObjet], $dicoDest);
|
|
log_write("indexObjet" .EOLH . print_r($result, true));
|
|
$objetMail = $result['text'];
|
|
$result = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest);
|
|
log_write("indexObjet" .EOLH . print_r($result, true));
|
|
$mailText = $result['text'];
|
|
$html = $result['html'];
|
|
if ( $html )
|
|
{
|
|
$message = "<html><head></head>\n<body>" . $message . "</body></html>";
|
|
}
|
|
saveMail( $db, $db->destMail, $objetMail, $mailText, $html);
|
|
}
|
|
|
|
function saveMail( $db, $destinataire, $objet, $text, $html=false)
|
|
{
|
|
$query = "INSERT INTO courriels VALUES ('0', '" . $db->protect($destinataire) . "', '" . $db->protect($objet) . "', '" . $db->protect($text) . "', '" . (int)$html . "')";
|
|
$db->query($query);
|
|
}
|
|
|
|
function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
|
|
{
|
|
$headers = "From: contact@avion-poe.me" . LF;
|
|
if ( !empty($cc)) $headers .= "Cc: " . $cc . LF;
|
|
if ( !empty($bcc)) $headers .= "Bcc: " . $bcc . LF;
|
|
|
|
if ($html)
|
|
{
|
|
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
|
|
nl2br($text);
|
|
}else
|
|
{
|
|
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
|
|
$text = str_replace("\n","\r\n", $text);
|
|
}
|
|
$headers .= "DATE: " . date( 'r' ) . LF . LF;
|
|
$destinataire = "dtux@free.fr";
|
|
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
|
|
if( !mail($destinataire, $sujet, wordwrap($text, 1000 , "\r\n"), $headers) ) //Sending mail
|
|
{
|
|
$error = error_get_last();
|
|
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet . EOL . print_r($error, true) . EOL . wordwrap($text, 1000 , "\r\n"), ERROR);
|
|
return false;
|
|
}else
|
|
{
|
|
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti: " . $destinataire . EOL . "text:" . $text, INFO);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
?>
|