- added mail return address to expeditor of ap\n- debug of error on peripetie datetime
This commit is contained in:
parent
ecf570ee87
commit
4dd37cda7b
40
cron.php
40
cron.php
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
//chdir('/var/www/html/avion-poeme/');
|
||||
|
||||
require_once 'session_init.php';
|
||||
require_once 'config.inc.php';
|
||||
require_once 'db.class.php';
|
||||
@ -9,11 +10,10 @@
|
||||
$db = new db();
|
||||
//test();
|
||||
$_SERVER["PHP_AUTH_USER"] = "cron";
|
||||
//peripetieDatee();
|
||||
print "envoi des courriers en attente" . EOLH;
|
||||
//peripetieDatee(); // désactivée pour l'instant
|
||||
envoiCourrielEnattente();
|
||||
print "envoi des péripéties" . EOLH;
|
||||
peripeties();
|
||||
//peripeties();
|
||||
print "Envoi des arrivées" . EOLH;
|
||||
arrivee();
|
||||
anonymisation();
|
||||
@ -62,6 +62,7 @@
|
||||
$dbPeripetie->query($query);
|
||||
$peripeties = $dbPeripetie->result->fetch_all(MYSQLI_ASSOC);
|
||||
$dbPeripetie->close();
|
||||
//print_r($peripeties);
|
||||
foreach ( $peripeties as $peripetie)
|
||||
{
|
||||
print "péripétie " . $peripetie["idAP"] . " - avion poème n° " . $peripetie['idAvion'] .EOLH;
|
||||
@ -77,11 +78,15 @@
|
||||
$dicoExpe = getLang( $db->expeLang );
|
||||
$dicoDest = getLang( $db->destLang );
|
||||
// TODO calcul de la nouvelle date d'arrivée
|
||||
$dateExpe = new DateTime("@$db->startTime");
|
||||
$dateDest = new DateTime("@$db->deliveryTime");
|
||||
$startTime = date("c", $db->startTime);
|
||||
$deliveryTime = date("c", $db->deliveryTime);
|
||||
$dateExpe = new DateTime($startTime);
|
||||
print_r($dateExpe);
|
||||
$dateDest = new DateTime($deliveryTime);
|
||||
print_r($dateDest);
|
||||
$interval = $dateExpe->diff($dateDest);
|
||||
$numericInterval = (($interval->days*24 + $interval->h)*60 + $interval->i)*60 + $interval->s;
|
||||
$addDate = $numericInterval * 15/100;
|
||||
$addDate = $numericInterval * 15/100; //TODO calculer d'après les données de la péripétie(voir table péripétie de la base de données)
|
||||
$db->deliveryTime += $addDate;
|
||||
$db->deliveryTimeServer += $addDate;
|
||||
$query = "UPDATE avionpoeme SET deliveryTime=FROM_UNIXTIME(" . $db->deliveryTime . "), deliveryTimeServer=FROM_UNIXTIME(" . $db->deliveryTimeServer . ") WHERE idAvion='" . $peripetie['idAvion'] . "'" ;
|
||||
@ -96,24 +101,23 @@
|
||||
//$html = $result['html'];
|
||||
sleep(1);
|
||||
print "envoi courriel à l'expéditeur : " . $db->expeMail . EOLH . $mailText .EOLH;
|
||||
$r = envoiMail( $db->expeMail, $objetMail, $mailText);
|
||||
$r = envoiMail("contact@avion-poe.me", $db->expeMail, $objetMail, $mailText);
|
||||
$db->datePeripetie = formatteDate($db->destLang, $db->deliveryTime, $db->deliveryTZ);
|
||||
$result = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest);
|
||||
$objetMail = $result["text"];
|
||||
$result = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest);
|
||||
$mailText = $result["text"];
|
||||
print "envoi courriel au destinataire : " . $db->destMail . EOLH . $mailText .EOLH;
|
||||
$s = envoiMail( $db->destMail, $objetMail, $mailText);
|
||||
$s = envoiMail($db->expeMail, $db->destMail, $objetMail, $mailText);
|
||||
sleep(1);
|
||||
//print "r=" . $r ." => s=" .$s .EOLH;
|
||||
|
||||
if ($r AND $s)
|
||||
{
|
||||
$query = "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'";
|
||||
$db->query($query);
|
||||
}else
|
||||
{
|
||||
print "table avion péripétie non mise à jour" .EOL;
|
||||
print "table avion péripétie non mise à jour" . EOL;
|
||||
print "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'" .EOLH;
|
||||
}
|
||||
|
||||
@ -135,7 +139,7 @@
|
||||
//var_dump($avionArrive);
|
||||
foreach ($avionArrive as $avion)
|
||||
{
|
||||
print "avion poème n° " . $avion['idAvion'] . "a atterri" . EOLH;
|
||||
print "avion poème n° " . $avion['idAvion'] . " a atterri" . EOLH;
|
||||
$dicoExpe = getLang( $avion['expeLang'] );
|
||||
$dicoDest = getLang( $avion['destLang'] );
|
||||
|
||||
@ -146,7 +150,7 @@
|
||||
$result = replaceVariables((object)$avion, $dicoExpe[$index], $dicoExpe);
|
||||
$mailText= $result["text"];
|
||||
print "envoi courriel à l'expéditeur : " . $avion['expeMail'] . EOLH . $mailText .EOLH;
|
||||
$r = envoiMail( $avion['expeMail'], $objetMail["text"], $mailText);
|
||||
$r = envoiMail("contact@avion-poe.me", $avion['expeMail'], $objetMail["text"], $mailText);
|
||||
|
||||
//envoi notification arrivée destinataire
|
||||
$index = "Notification_Arrivee_Destinataire";
|
||||
@ -159,14 +163,14 @@
|
||||
$mailText = "<html><head></head>\n<body>" . $mailText . "</body></html>";
|
||||
}
|
||||
print "envoi courriel au destinataire : " . $avion['destMail'] . EOLH . $mailText .EOLH;
|
||||
sleep(1);
|
||||
$s = envoiMail( $avion['destMail'], $objetMail["text"], $mailText, $html);
|
||||
sleep(3);
|
||||
$s = envoiMail($avion['expeMail'], $avion['destMail'], $objetMail["text"], $mailText, $html);
|
||||
if ($r AND $s)
|
||||
{
|
||||
$query = "UPDATE avionpoeme SET atteri=true WHERE idAvion='" . $avion['idAvion'] ."'";
|
||||
$db->query($query);
|
||||
}
|
||||
sleep(1);
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,13 +182,14 @@
|
||||
$courriels = $db->result->fetch_all(MYSQLI_ASSOC);
|
||||
foreach( $courriels as $courriel)
|
||||
{
|
||||
$r = envoiMail( $courriel['destinataire'], $courriel['objet'], $courriel['message'], $courriel['html']);
|
||||
//TODO changer l'expéditeur, doit être l'expéditeur de l'avion-poême.
|
||||
$r = envoiMail("contact@avion-poe.me", $courriel['destinataire'], $courriel['objet'], $courriel['message'], $courriel['html']);
|
||||
if ($r)
|
||||
{
|
||||
$query = "DELETE FROM courriels WHERE id='" . $courriel['id'] . "'";
|
||||
$db->query($query);
|
||||
}
|
||||
sleep(1);
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,3 +218,4 @@
|
||||
}
|
||||
}
|
||||
$db->close();
|
||||
?>
|
||||
|
@ -7,7 +7,6 @@ if (!isset($site)) {
|
||||
require_once "config.inc.php";
|
||||
require_once "log.php";
|
||||
require_once "fonctions.inc.php";
|
||||
require_once "envoi_courriel.inc.php";
|
||||
|
||||
$table_prefix = "";
|
||||
class db
|
||||
@ -197,10 +196,17 @@ class db
|
||||
function savePeripetie()
|
||||
{
|
||||
|
||||
$query = "INSERT INTO avionPeripetie VALUES ('0','";
|
||||
$query .= $this->protect($this->uid) . "','";
|
||||
$query .= $this->protect($this->idPeripetie) . "', ";
|
||||
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "), '0')";
|
||||
$query = "INSERT INTO avionPeripetie ('expeMail', 'idAvion', 'idPeripetie', 'date'), VALUES (";
|
||||
if ($this->expeKnown)
|
||||
{
|
||||
$query .= "'" . $this->protect($this->expeMail) . "',";
|
||||
}else
|
||||
{
|
||||
$query .= "'contact@avion-poe.me',";
|
||||
}
|
||||
$query .= "'" . $this->protect($this->uid) . "',";
|
||||
$query .= "'" . $this->protect($this->idPeripetie) . "', ";
|
||||
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "))";
|
||||
log_write("savePeripetie " . $query);
|
||||
//$query .= $this->protect($this->effetPeripetie) . "', '";
|
||||
//$query .= $this->protect($this->expeMail) . "', '";
|
||||
|
@ -2,7 +2,6 @@
|
||||
require_once 'log.php';
|
||||
require_once 'fonctions.inc.php';
|
||||
|
||||
|
||||
function courrielEnvoi( $db )
|
||||
{
|
||||
$dicoExpe = getLang( $db->expeLang );
|
||||
@ -56,43 +55,50 @@ function saveMail( $db, $expediteur, $destinataire, $objet, $text, $html=false)
|
||||
$db->query($query);
|
||||
}
|
||||
|
||||
function envoiMail($expediteur,$destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
|
||||
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';
|
||||
$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)
|
||||
try
|
||||
{
|
||||
// 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);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
$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))
|
||||
catch (\Swift_TransportException $ex)
|
||||
{
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user