DTux
/
dtux__avion-poeme
Archived
1
0
Fork 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

107 lines
3.6 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'];
saveMail( $db, "contact@avion-poe.me", $db->expeMail, $objetMail, $mailText, $html);
//log_write(print_r($db,true));
// message au destinataire
if ( $db->expeKnown == 'true' )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
//log_write("Expéditeur connu => ");
}else
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
//log_write("Expéditeur inconnu => ");
}
$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->expeMail, $db->destMail, $objetMail, $mailText, $html);
}
function saveMail( $db, $expediteur, $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($expediteur, $destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
{
require_once 'include/swiftmailer/autoload.php';
//require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php';
try
{
$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');
if ($html)
{
// 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);
}else
{
$type->setValue('text/plain');
$type->setParameter('charset', 'utf-8');
$text = str_replace("\n","\r\n", $text);
}
$message->setBody($text);
//add date header
$headers = $message->getHeaders();
//$headers->addDateHeader('Date', new DateTimeImmutable('3 days ago'));
$headers->addPathHeader('Return-Path', $expediteur);
if (!$mailer->send($message, $failures))
{
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);
return false;
}
}
catch (\Swift_TransportException $ex)
{
return false;
}
return true;
}
?>