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

70 lines
2.2 KiB
PHP
Raw Normal View History

2021-03-22 12:20:39 +01:00
<?php
require_once 'log.php';
2021-04-29 10:32:58 +02:00
require_once 'fonctions.inc.php';
2021-03-22 12:20:39 +01:00
2021-04-07 21:08:08 +02:00
function courrielEnvoi( $db )
{
$dicoExpe = getLang( $db->expeLang );
$dicoDest = getLang( $db->destLang );
$expediteurIndex = "Notification_denvoi_Expediteur";
//print "envoi du courriel" . EOL;
2021-04-29 10:32:58 +02:00
// Message à l'expéditeur
$indexObjet = "Objet_" . $expediteurIndex;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) .EOL .EOL ;
2021-04-07 21:08:08 +02:00
if ( $db->expeKnown == false )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
}else
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
}
2021-04-29 10:32:58 +02:00
saveMail( $db, $db->expeMail, $objetMail, $mailText);
2021-04-07 21:08:08 +02:00
2021-04-29 10:32:58 +02:00
// message au destinataire
2021-04-07 21:08:08 +02:00
$indexObjet = "Objet_" . $destinataireIndex;
2021-04-29 10:32:58 +02:00
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest) .EOL .EOL ;
saveMail( $db, $db->destMail, $objetMail, $mailText);
2021-04-07 21:08:08 +02:00
}
2021-04-29 10:32:58 +02:00
function saveMail( $db, $destinataire, $objet, $text, $html=FALSE)
2021-04-07 21:08:08 +02:00
{
2021-04-29 10:32:58 +02:00
$query = "INSERT INTO courriels VALUES ('0', '" . $db->protect($destinataire) . "', '" . $db->protect($objet) . "', '" . $db->protect($text) . "', '" . (int)$html . "')";
$db->query($query);
2021-04-07 21:08:08 +02:00
}
2021-03-23 20:26:52 +01:00
2021-04-29 10:32:58 +02:00
function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
2021-03-22 12:20:39 +01:00
{
$headers = "From: contact@avion-poe.me" . LF;
2021-04-29 10:32:58 +02:00
if ( !empty($cc)) $headers .= "Cc: " . $cc . LF;
if ( !empty($bcc)) $headers .= "Bcc: " . $bcc . LF;
if (empty($html))
2021-03-22 12:20:39 +01:00
{
2021-04-29 10:32:58 +02:00
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
2021-03-22 12:20:39 +01:00
}else
2021-03-23 20:26:52 +01:00
{
2021-04-29 10:32:58 +02:00
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
nl2br($text);
2021-03-22 12:20:39 +01:00
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
2021-04-29 10:32:58 +02:00
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
2021-04-07 21:08:08 +02:00
if( !mail($destinataire, $sujet, wordwrap($text, 70 , "\r\n"), $headers) ) //Sending mail
2021-03-22 12:20:39 +01:00
{
2021-04-29 10:32:58 +02:00
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet, ERROR);
return false;
2021-03-22 12:20:39 +01:00
}else
{
2021-04-29 10:32:58 +02:00
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti: " . $destinataire . EOL . "text:" . $text, INFO);
return true;
2021-03-22 12:20:39 +01:00
}
}
2021-03-23 20:26:52 +01:00
?>