1
0

version fonctionnelle

This commit is contained in:
Daniel Tartavel
2021-06-17 18:35:51 +02:00
parent 3c303efeb9
commit ab2f9b87a7
243 changed files with 23955 additions and 100 deletions

View File

@ -19,20 +19,22 @@ function courrielEnvoi( $db )
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>";
}
if ( $db->expeKnown == false )
saveMail( $db, $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 => ");
}
saveMail( $db, $db->expeMail, $objetMail, $mailText, $html);
// message au destinataire
$indexObjet = "Objet_" . $destinataireIndex;
$result = replaceVariables($db, $dicoDest[$indexObjet], $dicoDest);
log_write("indexObjet" .EOLH . print_r($result, true));
@ -56,32 +58,42 @@ function saveMail( $db, $destinataire, $objet, $text, $html=false)
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;
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');
if ($html)
{
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
nl2br($text);
// 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
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
$type->setValue('text/plain');
$type->setParameter('charset', 'utf-8');
$text = str_replace("\n","\r\n", $text);
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
$destinataire = "dtux@free.fr";
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
if( !mail($destinataire, $sujet, wordwrap($text, 1000 , "\r\n"), $headers) ) //Sending mail
$message->setBody($text);
//add date header
$headers = $message->getHeaders();
$headers->addDateHeader('Your-Header', new DateTimeImmutable('3 days ago'));
if (!$mailer->send($message, $failures))
{
$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);
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;
}else
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti: " . $destinataire . EOL . "text:" . $text, INFO);
return true;
}
return true;
}
?>