8768 sujets

Développement web côté serveur, CMS

Bonjour,

je viens encore une fois car PhPMailer me cause problème.

Dans un précédent sujet, j'avais posté un code de newsletter qui fonctionnait parfaitement
nous l'avons un tout petit peu retoucher avec mon coadministrateur et depuis plus rien ne va.
Voici le problème suivit du code :

problème=la page ne charge même plus et donc les mails de newsletter ne s'envoient pas, et aucune erreur ne veut s'afficher.

Code :

<?php
ini_set('display_errors', 1);
error_reporting(e_all);
require('/var/www/vhosts/accessibiliteprogrammes.fr/dev.progaccess33.net/PHPMailer-master/PHPMailerAutoload.php');
/* Ce programme envoie automatiquement la newsletter et nettoye la table. */

include('dbconnect.php');

# Netoyage de la table
$req = $bdd->prepare('DELETE FROM newsletter_mails WHERE expire<?');
$req->execute(array(time()));

# Sélection des mails
$r = '(freq=1';
if(localtime()[3] == 1)# premier jour du mois
$r .= ' OR freq=5';
if(localtime()[6] == 1 and intval(date('W'))%2 == 0)# lundi et semaine paire
$r .= ' OR freq=4';
if(localtime()[6] == 1)# lundi
$r .= ' OR freq=3';
if(localtime()[7]%2 == 0)# jour pair sur l'année
$r .= ' OR freq=2';
$r .= ')';

# Lister les catégories
$cat = array();
$req = $bdd->query('SELECT * FROM softwares_categories');
while($data = $req->fetch()) {$cat[$data['id']] = $data['name'];}

# Prendre des infos à envoyer
$req = $bdd->prepare('SELECT * FROM softwares WHERE date>=? ORDER BY date DESC');
$req->execute(array(time()-2678400));# récents d'au plus un mois
$sft = array();
while($data = $req->fetch()) {
$sft[] = $data;
}

$req = $bdd->prepare('SELECT * FROM softwares_files WHERE date>=? ORDER BY date DESC');
$req->execute(array(time()-2678400));# récents d'au plus un mois
$files = array();
while($data = $req->fetch()) {
$files[] = $data;
}

$message1 = "<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\" />
<title>Newsletter ProgAccess33</title>
<style type=\"text/css\">
@font-face {font-family: Cantarell;src: url(https://progaccess33.net/css/Cantarell-Regular.otf);}
html, body {margin: 0;padding: 0;font-family: Cantarell;}
.software {border-left: 2px dashed black;padding-left: 10px;}
.software_title {margin-bottom: -8px;}
.software_date {color: #606060;margin-left: 15px;}
.software_hits, .software_category {color: #008000;}
</style>
</head>
<body>
<div id=\"header\">
<img id=\"logo\" alt=\"Logo\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAVi0lEQVR4nO1daVBUR9fumQEGRmE2BnBDwBiJn69GxQUZg4BljIkWxPUzlgoTTcWExS9YlWBckrjEJa+JSSzXuCQaTalEDZgYfEUrC1HcSESRWC5xoQYE3JIYhOf7gbedO32HubPq69yn6hTDmXu6z+1+bm+3+wyBBJ8GedgOSHi4kAjg45AI4OOQCODjkAjg45AI4OOQCODjkAjg45AI4OOQCODjkAjg45AI4OOQCODjkAjg45AI4OOQCODjkAjg45AI4OPwKAHq6upQX18viZPy999/e7J6AHiYAGFhYSCESOKkrFu3zpPVA8DDBDAYDA+9EP+bZe3atZ6sHgASAR5pkVoAHxeJAD4uEgF8XCQC+LhIBPBxeewJcODAAdTU1HhFamtrsXr1amRmZiIzMxM3btzwWt5CcuPGDSQnJ/s2AY4fPw4AaGpq8rgAwMqVK2neNTU1bk3b0fsAgKFDh0oE8CZ+/fVXmvehQ4fclq41EcTCHgEe+4UgbxMAABQKBQghWLZsmVvTlQgggEeJADU1NaisrET79u1BCEG3bt2wceNGbN26FXv37kVpaSmqqqq85g8gEcCjBDCbzVi5ciUGDx6MkJAQ0SPvwMBA9O3bF3PnzsWJEyc85h8gEcAjBFizZg169+7ttqmYXq/H1KlTUVlZ6XZfpUGgmwjQ1NSEZcuWoXXr1jbzSkxMREFBAf744w/4+/uDEILc3FyUl5fju+++Q25uLsLDw1v0d9iwYfjtt9/c4jMgEcAtBNixY4dgE5+dnY2LFy9iyJAhIISgb9++1CY+Ph6EEPTs2ZNJb/78+bx0uEGjpYwfPx4NDQ0u+y4RwAUC3L59G0lJSbz0nnrqKSiVShBC8MknnwAANm/eTL8HgLKyMsTFxdH+/sMPP8QPP/z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excuses</h2>
<p>Suites à quelques tests lors de la résolution d\'un bug entraînant la réception en spam de nos newsletters, un nombre considérable de mails a été envoyé avant la version 12.2 du site.<br />
Nous vous prions de nous en excuser.<br />
Nous mettons tout en œuvre pour améliorer la qualité de notre service. Si toutefois un problème survenait, merci de nous en informer via le formulaire de contact accessible sur le site internet.</p>
</div>
<div id=\"content\">
<h2>Nouveaux logiciels et mises à jour</h2>";
$message2 = '<a id="link" href="https://progaccess33.net/nlmod.php?id=';
$message3 = '">Cliquez ici pour modifier les paramètres de votre abonnement ou vous désinscrire.</a>
<p>Ce mail a été envoyé automatiquement, merci de ne pas répondre.</p>
<p>Cordialement,<br />L\'équipe ProgAccess33</p>
</div>
</body>
</html>';

$subject = 'Newsletter ProgAccess33 et message important';

# Envoi des mails
if(isset($_GET['debug'])) {
$req = $bdd->prepare('SELECT * FROM newsletter_mails WHERE confirm=1 AND mail=?');
$req->execute(array($_GET['debug']));
}
else
{
$req = $bdd->prepare('SELECT * FROM newsletter_mails WHERE confirm=1 AND '.$r);
$req->execute();
}
while($data = $req->fetch()) {
$message = $message1;
foreach($sft as $software) {
if($software['date'] > $data['lastmail']) {
$message .= '<hr /><div class="software"><a href="article.php?id='.$software['id'].'"><h2 class="software_title">'.$software['name'].'</h2></a><p><span class="software_category">('.$cat[$software['category']].')</span> '.$software['description'].'<br /><span class="software_hits">'.$software['hits'].' visites</span><span class="software_date"> (mise à jour le '.date('d/m/Y à H:i:s', $software['date']).')</span></p><ul>';
foreach($files as $file) {
if($file['sw_id'] == $software['id']) {
$message .= '<li>'.$file['title'].'</li>';
}
$message .= '</ul></div>';
}
}
if($message != $message1) {
$message .= $message2.$data['hash'].$message3;
$mail = newPHPMailer();
$mail->isSMTP();
$mail->Host = 'mail.zajda.fr';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply@progaccess33.net';
$mail->Password = 'Nmd$4n19';
$mail->setFrom('noreply@progaccess33.net', 'ProgAccess33');
$mail->addReplyTo('miklhcos@progaccess33.net', 'Admin');
$mail->addAddress($data['mail']);
$mail->Subject = $subject;
$mail->CharSet = 'UTF-8';
$mail->IsHTML(TRUE);
$mail->Body = $message;
$mail->send();
$req2 = $bdd->prepare('UPDATE newsletter_mails SET lastmail=? WHERE id=?');
$req2->execute(array(time(), $data['id']));
}
}
$req->closeCursor();
?>


je suis absolument pommé avec ce souci, help !!!!
Merci d'avance.
Bonjour,

Votre boucle while($data = $req->fetch()) {$message = $message1;... n'est pas fermée. C'est peut-être la cause du dysfonctionnement.


PS: j'ose imaginer que le mot de passe renseigné ici en clair est un fake... Autrement, n'oubliez pas d'en changer Smiley cligne
Bonsoir,

merci, mais même en rajoutant une accolade à la fin du passage indiqué, rien ne change Smiley decu

et merci aussi pour le mdp, je l'ai changé Smiley smile
Êtes-vous sûr que l'appel à ce script se fait correctement ? A l'occasion vous avez mal renseigné l'uri de cette page.

Car ce qui m'étonne c'est qu'aucune erreur ne soit reportée par le serveur (à l'écran et dans le log) donc il semble que rien ne s'exécute.

Si le script est correctement appelé, tentez de debugger en ajoutant un echo d'abord en tête de page, puis quelques instructions plus bas puis encore plus bas etc etc jusqu'à mettre le doigt sur la truffe.

D'ici, rien de suspect dans votre code. Smiley ohwell
Bonjour,
d'après mon coadmin qui a tenté une réparation, la table de la BDD est vide, mais on ne comprend pas pourquoi.
Je vous tiendrai informé de l'avancée de la situation
Bonsoir,

voilà, nous avons tout réparé, voici les étapes:
nous avons tout d'abord rerempli la bdd
ensuite, on a corrigé tous les soucis d'accolades et ajotué un truc qui dit ok et affiche un slash lorsqu'une adresse est bien prise en compte dans l'envoi.
Puisque tout semblait marcher mais que rien ne s'envoyait j'ai décidé de faire afficher les erreurs de PHPMailer, et il s'averrait que je m'étais également trompé de mdp pour le smtp.

Tout refonctionne donc: voici le code final :

<?php
require('/var/www/vhosts/accessibiliteprogrammes.fr/httpdocs/PHPMailer-master/PHPMailerAutoload.php');
/* Ce programme envoie automatiquement la newsletter et nettoye la table. */

include('dbconnect.php');

# Netoyage de la table
$req = $bdd->prepare('DELETE FROM newsletter_mails WHERE expire<?');
$req->execute(array(time()));

# Sélection des mails
$r = '(freq=1';
if(localtime()[3] == 1)# premier jour du mois
$r .= ' OR freq=5';
if(localtime()[6] == 1 and intval(date('W'))%2 == 0)# lundi et semaine paire
$r .= ' OR freq=4';
if(localtime()[6] == 1)# lundi
$r .= ' OR freq=3';
if(localtime()[7]%2 == 0)# jour pair sur l'année
$r .= ' OR freq=2';
$r .= ')';

# Lister les catégories
$cat = array();
$req = $bdd->query('SELECT * FROM softwares_categories');
while($data = $req->fetch()) {$cat[$data['id']] = $data['name'];}

# Prendre des infos à envoyer
$req = $bdd->prepare('SELECT * FROM softwares WHERE date>=? ORDER BY date DESC');
$req->execute(array(time()-2678400));# récents d'au plus un mois
$sft = array();
while($data = $req->fetch()) {
$sft[] = $data;
}

$req = $bdd->prepare('SELECT * FROM softwares_files WHERE date>=? ORDER BY date DESC');
$req->execute(array(time()-2678400));# récents d'au plus un mois
$files = array();
while($data = $req->fetch()) {
$files[] = $data;
}

$message1 = "<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\" />
<title>Newsletter ProgAccess33</title>
<style type=\"text/css\">
@font-face {font-family: Cantarell;src: url(https://progaccess33.net/css/Cantarell-Regular.otf);}
html, body {margin: 0;padding: 0;font-family: Cantarell;}
.software {border-left: 2px dashed black;padding-left: 10px;}
.software_title {margin-bottom: -8px;}
.software_date {color: #606060;margin-left: 15px;}
.software_hits, .software_category {color: #008000;}
</style>
</head>
<body>
<div id=\"header\">
<img id=\"logo\" alt=\"Logo\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAVi0lEQVR4nO1daVBUR9fumQEGRmE2BnBDwBiJn69GxQUZg4BljIkWxPUzlgoTTcWExS9YlWBckrjEJa+JSSzXuCQaTalEDZgYfEUrC1HcSESRWC5xoQYE3JIYhOf7gbedO32HubPq69yn6hTDmXu6z+1+bm+3+wyBBJ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mT0hl/Jk5gYx96Ch4nwJIlS5kNHU937ynKtrq6+v46O79w/7AK6OgI3E2Ay5cvM3N5GZEzwShtoUf3p63II8O/l/7baX8chccJ8O233zHNeJBSJdpeaC9BqVWsHUfg7i6g9H7IWstKVAWJf18RpFQx44d9+/Y57Y+j8DgBuCfEeiBoHTDJFqI6RvM2k3KbLp2FuwkgNIiLimRDwgrh2NFjAmUjw9WrV+wbuwle2RHUoV0k08wtXPC+KNvk5BSmgFzZPu1uAiwS2LOYkswGuxLCwgXvM0vTkR06Ou2LM/AKAcb/7wSm0Ht0F/fGS2jP3ahRo5z2xd0EGPniSOZ192uvvibKtnv3nszikTMHVV2BVwhQWFgouC3MOpyaELZt+4rfxxI/dIp5wmlf3E2AmKhOzAxg27Ztdu3Onz8vuB3MOjK5p+EVAjQ0NEDpH8g05fPnz7drW1FxVvCNmbOYOoVdCJrqwkKQ9bI2IQQVFfa3rM2fv4DpOpQBgWhoaHDaF2fgtZNBqalpzLq3Rq2FMeEZJAwYiIQBRiQMGAjjgIH3/2/W9Y3rxyyVyogcvXvFISHe+EC4NOj/Rqv/B8KYMBARYW3YpenwNkhIGPjARqT06hXH9OFyokDfuH4t+GGEMWEgNCFa/kkpokBa2khvVQfF/wNdhJyK9WTM+wAAAABJRU5ErkJggg==\" />
<h1>Newsletter ProgAccess33</h1>
</div>
<div id=\"content\">
<h2>Nouveaux logiciels et mises à jour</h2>";
$message2 = '<a id="link" href="https://progaccess33.net/nlmod.php?id=';
$message3 = '">Cliquez ici pour modifier les paramètres de votre abonnement ou vous désinscrire.</a>
<p>Ce mail a été envoyé automatiquement, merci de ne pas répondre.</p>
<p>Cordialement,<br />L\'équipe ProgAccess33</p>
</div>
</body>
</html>';

$subject = 'Newsletter ProgAccess33';

# Envoi des mails
if(isset($_GET['debug'])) {
$req = $bdd->prepare('SELECT * FROM newsletter_mails WHERE confirm=1 AND mail=?');
$req->execute(array($_GET['debug']));
echo "--debug--\n";
}
else
{
$req = $bdd->prepare('SELECT * FROM newsletter_mails WHERE confirm=1 AND '.$r);
$req->execute();
echo "--prod--\n";
}
while($data = $req->fetch()) {
$message = $message1;
foreach($sft as $software) {
if($software['date'] > $data['lastmail']) {
$message .= '<hr /><div class="software"><a href="article.php?id='.$software['id'].'"><h2 class="software_title">'.$software['name'].'</h2></a><p><span class="software_category">('.$cat[$software['category']].')</span> '.$software['description'].'<br /><span class="software_hits">'.$software['hits'].' visites</span><span class="software_date"> (mise à jour le '.date('d/m/Y à H:i:s', $software['date']).')</span></p><ul>';
foreach($files as $file) {
if($file['sw_id'] == $software['id'])
$message .= '<li>'.$file['title'].'</li>';
}
$message .= '</ul></div>';
}
}
echo $data['mail'];
if($message != $message1) {
echo ' OK';
$message .= $message2.$data['hash'].$message3;
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.zajda.fr';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'no_reply@progaccess33.net';
$mail->Password = '';
$mail->setFrom('noreply@progaccess33.net', 'ProgAccess33');
$mail->addReplyTo('miklhcos@progaccess33.net', 'Admin');
$mail->addAddress($data['mail']);
$mail->Subject = $subject;
$mail->CharSet = 'UTF-8';
$mail->IsHTML(TRUE);
$mail->Body = $message;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
$req2 = $bdd->prepare('UPDATE newsletter_mails SET lastmail=? WHERE id=?');
$req2->execute(array(time(), $data['id']));
}
echo " /\n";
}
$req->closeCursor();
?>