1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__avion-poeme/include/envoi_courriel.inc.php
Daniel Tartavel 7e015a3d1b v1
2021-04-29 10:32:58 +02:00

70 lines
2.2 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;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) .EOL .EOL ;
if ( $db->expeKnown == false )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
}else
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
}
saveMail( $db, $db->expeMail, $objetMail, $mailText);
// message au destinataire
$indexObjet = "Objet_" . $destinataireIndex;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest) .EOL .EOL ;
saveMail( $db, $db->destMail, $objetMail, $mailText);
}
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 (empty($html))
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
}else
{
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
nl2br($text);
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
if( !mail($destinataire, $sujet, wordwrap($text, 70 , "\r\n"), $headers) ) //Sending mail
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet, ERROR);
return false;
}else
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti: " . $destinataire . EOL . "text:" . $text, INFO);
return true;
}
}
?>