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

88 lines
2.9 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;
2021-05-31 12:27:51 +02:00
$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>";
}
2021-04-07 21:08:08 +02:00
if ( $db->expeKnown == false )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
}else
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
}
2021-05-31 12:27:51 +02:00
saveMail( $db, $db->expeMail, $objetMail, $mailText, $html);
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-05-31 12:27:51 +02:00
$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);
2021-04-07 21:08:08 +02:00
}
2021-05-31 12:27:51 +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;
2021-05-31 12:27:51 +02:00
if ($html)
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-05-31 12:27:51 +02:00
}else
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
$text = str_replace("\n","\r\n", $text);
2021-03-22 12:20:39 +01:00
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
2021-05-31 12:27:51 +02:00
$destinataire = "dtux@free.fr";
2021-04-29 10:32:58 +02:00
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
2021-05-31 12:27:51 +02:00
if( !mail($destinataire, $sujet, wordwrap($text, 1000 , "\r\n"), $headers) ) //Sending mail
2021-03-22 12:20:39 +01:00
{
2021-05-31 12:27:51 +02:00
$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);
2021-04-29 10:32:58 +02:00
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
?>