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

101 lines
3.4 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'];
2021-06-17 18:35:51 +02:00
saveMail( $db, "contact@avion-poe.me", $db->expeMail, $objetMail, $mailText, $html);
2021-06-17 18:35:51 +02:00
//log_write(print_r($db,true));
// message au destinataire
if ( $db->expeKnown == 'true' )
2021-04-07 21:08:08 +02:00
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
2021-06-17 18:35:51 +02:00
//log_write("Expéditeur connu => ");
2021-04-07 21:08:08 +02:00
}else
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
2021-06-17 18:35:51 +02:00
//log_write("Expéditeur inconnu => ");
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->expeMail, $db->destMail, $objetMail, $mailText, $html);
2021-04-07 21:08:08 +02:00
}
function saveMail( $db, $expediteur, $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
function envoiMail($expediteur,$destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
2021-03-22 12:20:39 +01:00
{
2021-06-17 18:35:51 +02:00
require_once 'include/swiftmailer/autoload.php';
//require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php';
$transport = (new Swift_SmtpTransport('smtpauth.online.net', 465, 'ssl'))
->setUsername('contact@avion-poe.me')
->setPassword('AvionPoème*27juillet');
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message($sujet))
->setFrom(["contact@avion-poe.me"])
->setTo([$destinataire])
->setCharset('utf-8');
$type = $message->getHeaders()->get('Content-Type');
2021-05-31 12:27:51 +02:00
if ($html)
2021-03-23 20:26:52 +01:00
{
2021-06-17 18:35:51 +02:00
// setParameters() takes an associative array
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');
$str = nl2br($text);
$text = "<html><head></head>\n<body>" . $str . "</body></html>";
log_write(__FILE__ . EOL . __LINE__ . EOL . wordwrap($text, 1000, "\r\n"), INFO);
2021-05-31 12:27:51 +02:00
}else
{
2021-06-17 18:35:51 +02:00
$type->setValue('text/plain');
$type->setParameter('charset', 'utf-8');
2021-05-31 12:27:51 +02:00
$text = str_replace("\n","\r\n", $text);
2021-03-22 12:20:39 +01:00
}
2021-06-17 18:35:51 +02:00
$message->setBody($text);
//add date header
$headers = $message->getHeaders();
//$headers->addDateHeader('Date', new DateTimeImmutable('3 days ago'));
$headers->addPathHeader('Return-Path', $expediteur);
2021-06-17 18:35:51 +02:00
if (!$mailer->send($message, $failures))
2021-03-22 12:20:39 +01:00
{
2021-06-17 18:35:51 +02:00
echo "Failures:";
print_r($failures);
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" . $destinataire . EOL . $sujet . EOL . print_r($failure, 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
}
2021-06-17 18:35:51 +02:00
return true;
2021-03-22 12:20:39 +01:00
}
2021-03-23 20:26:52 +01:00
?>