OVH Community, votre nouvel espace communautaire.

Mailing envoyé 5 fois


stephaneeybert
03/04/2012, 17h33
J'ai remis le sleep, et le probleme s'est repose.

Du coup je l'ai retire.

Ce qui se passe, c'est que j'ai un autre probleme.

Mon utilisateur recoit pleins de mails en retour, plus de 1500, sur une liste d'envoi de 3000 destinataires.

Je ne sais que faire...

stephaneeybert
20/02/2012, 21h41
J'ai supprime le sleep(1)
et modifie le code pour avoir cela:

// Mark the email address as having been sent the email to
if ($cloneMailOutbox = $mailOutboxUtils->cloneMailOutbox($mailOutbox)) {
// A cloned object is used to work around the most puzzling of bugs
// as updating the object being looped on appears to make the loop having missteps
$cloneMailOutbox->setSent(1);
$mailOutboxUtils->update($cloneMailOutbox);
}

Ceci afin d'eviter de modifier l'objet courant de la boucle.

Ca devrait etre bon maintenant.

stephaneeybert
10/02/2012, 20h26
Car sans le sleep(1) le probleme ne se pose pas.

stephaneeybert
10/02/2012, 16h59
Au fait, est ce que ca aide le mail system d'avoir un sleep(1) dans ma boucle ?

stephaneeybert
10/02/2012, 08h25
@chris31
Pour aller dans ton sens, un test precedent a montre que si le sleep(1) etait commente alors le probleme ne se posait pas.
Je vais mettre le sleep(1) en fin d'iteration et voir ce que cela donne.
Merci.

Nowwhat
09/02/2012, 22h39
Citation Envoyé par stephaneeybert
La taille d'un "foreach ($mailOutboxes as $mailOutbox)" (donc: $mailOutBoxes) une fois la boucle lancé ? Heu... Je trouve cette information facilement ?
Oui.
http://php.net/manual/fr/function.sizeof.php
donc
Code PHP:
echo sizeof($mailOutboxes); 

chris31
09/02/2012, 22h32
Est-ce que ton problème n'est pas plutôt lié à une question de durée d'exécution?
C'est le fait que tu dises que ton script fonctionne correctement sur un autre hébergement et que chez OVH il se dérègle tous les qq 1000 itérations.
Le groupe d'instruction :
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox);
ne génère-t-il pas de temps en temps sur le serveur une tâche d'accroissement de buffer ou quelque chose de ce type (en asynchrone donc sans mettre ton script en veille) qui fait que ta variable de boucle serait parfois invalide lorsqu'elle est évaluée.
J'essaierai de mettre une temporisation après le dernier groupe d'instruction (donc en fin de chaque itération).

stephaneeybert
09/02/2012, 17h52
La taille d'un "foreach ($mailOutboxes as $mailOutbox)" (donc: $mailOutBoxes) une fois la boucle lancé ? Heu... Je trouve cette information facilement ?

Nowwhat
09/02/2012, 15h57
C'est quoi la taille d'un "foreach ($mailOutboxes as $mailOutbox)" (donc: $mailOutBoxes) une fois la boucle lancé ?Il est quasi sur maintenant que pour une raison inconnu littérateur de foreach perds la route après avoir piogé 2000 copies de "$mailOutbox" ...
Il me semble que l’injection de ce "1" y est pour quelque chose...

Faut le dire: c'est relativement casse tête ...

stephaneeybert
09/02/2012, 15h43
J'ai fais le test en commentant les deux lignes
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox);
et effectivement il n'y a pas eu de probleme de repetition.

Je vais donc modifier le script pour ne modifier les objets qu'une fois la boucle terminee, au besoin en faisant deux boucles.

Nowwhat
09/02/2012, 11h22
Noop.
Ce qui ce passe en réalité, on y encore loin.
Par contre, ce qui est fort probable, est que le
foreach ($mailOutboxes as $mailOutbox)
déraille.

Est-ce que $mailOutboxes reste la même ...
Sachant que
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox);

opère sur cet array (il va insérer une variable, NULL avant, valeur 1 après).
Donc tout un pavé en méoire est en train d'agrandir chaque fois un poil.

Test à faire: enlève
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox);

pendant une phase de test

stephaneeybert
09/02/2012, 10h14
@Nowwhat
Pour confirmation, tu me dis que le update() qui se trouve au sein de la boucle affecterais le selectUnsent() qui produit les elements nourissant la boucle ?
Comment cela se pourrait il ? Les elements retournes par selectUnsent() le sont avant que la boucle n'est commence. Pourquoi un update() au sein de la boucle opererait sur le precedent ordre sql...

Merci.

Nowwhat
08/02/2012, 21h23
Humm.

Énigmatique.

Indice possible: dans ton boucle, imprime aussi le mémoire utilisé/libre/etc.

Il me semble que ceci:
Code PHP:
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox); 
qui opère sur
Code PHP:
$this->querySelect($sqlStatement
cesse de fonctionner.

stephaneeybert
08/02/2012, 20h02
On voit que le test est revelateur:

[Wed Feb 08 21:00:33 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@comhem.se
[Wed Feb 08 21:00:33 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@comhem.se
[Wed Feb 08 21:00:33 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@comhem.se
[Wed Feb 08 21:00:34 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@primeminister.ministry.se
[Wed Feb 08 21:00:34 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@primeminister.ministry.se
[Wed Feb 08 21:00:34 2012] [error] [client 46.105.8.54] =========>> outbox: kristina.zetterstrom@primeminister.ministry.se

stephaneeybert
08/02/2012, 20h01
Je viens de faire un test, en commentant l'appel a LibEmail::send
// LibEmail::sendMail($email, "$firstname $lastname", $subject, $mailBody, $senderEmail, $senderName, $attachedImages, $attachedFiles, $inTextFormat);
ainsi qu'en commentant l'appel a sleep(1);
// sleep(1);

Du coup, la boucle a ete tres vite, presqu'instantanee.

Et il n'y a pas eu de doublons cette fois ci.

Chaque object a bien ete traite une seule fois dans la boucle.

J'ai ensuite fais un 2eme test.

Cette fois ci, j'ai toujours commente l'appel a LibEmail::send
// LibEmail::sendMail($email, "$firstname $lastname", $subject, $mailBody, $senderEmail, $senderName, $attachedImages, $attachedFiles, $inTextFormat);
mais j'ai laisse le sleep(1) actif de maniere a avoir une seconde d'attente entre chaque objet.

Et bien, a ma surprise, le probleme s'est pose !

Voila ce qu'affiche la log:

[Wed Feb 08 20:54:20 2012] [error] [client 46.105.8.54] =========>> outbox: jennysund@hotmail.com
[Wed Feb 08 20:54:20 2012] [error] [client 46.105.8.54] =========>> outbox: jennysund@hotmail.com
[Wed Feb 08 20:54:20 2012] [error] [client 46.105.8.54] =========>> outbox: jennysund@hotmail.com
[Wed Feb 08 20:54:21 2012] [error] [client 46.105.8.54] =========>> outbox: jennyzasa@hotmail.com
[Wed Feb 08 20:54:21 2012] [error] [client 46.105.8.54] =========>> outbox: jennyzasa@hotmail.com
[Wed Feb 08 20:54:21 2012] [error] [client 46.105.8.54] =========>> outbox: jennyzasa@hotmail.com
[Wed Feb 08 20:54:22 2012] [error] [client 46.105.8.54] =========>> outbox: jenny_mery@campeon.se
[Wed Feb 08 20:54:22 2012] [error] [client 46.105.8.54] =========>> outbox: jenny_mery@campeon.se
[Wed Feb 08 20:54:22 2012] [error] [client 46.105.8.54] =========>> outbox: jenny_mery@campeon.se
[Wed Feb 08 20:54:23 2012] [error] [client 46.105.8.54] =========>> outbox: jens.pohl@vinge.se
[Wed Feb 08 20:54:23 2012] [error] [client 46.105.8.54] =========>> outbox: jens.pohl@vinge.se
[Wed Feb 08 20:54:23 2012] [error] [client 46.105.8.54] =========>> outbox: jens.pohl@vinge.se
[Wed Feb 08 20:54:24 2012] [error] [client 46.105.8.54] =========>> outbox: jens.westlund@telia.com
[Wed Feb 08 20:54:24 2012] [error] [client 46.105.8.54] =========>> outbox: jens.westlund@telia.com
[Wed Feb 08 20:54:24 2012] [error] [client 46.105.8.54] =========>> outbox: jens.westlund@telia.com
[Wed Feb 08 20:54:25 2012] [error] [client 46.105.8.54] =========>> outbox: jens@free.se
[Wed Feb 08 20:54:25 2012] [error] [client 46.105.8.54] =========>> outbox: jens@free.se
[Wed Feb 08 20:54:25 2012] [error] [client 46.105.8.54] =========>> outbox: jens@free.se
[Wed Feb 08 20:54:26 2012] [error] [client 46.105.8.54] =========>> outbox: jens@samuelsson.nu
[Wed Feb 08 20:54:26 2012] [error] [client 46.105.8.54] =========>> outbox: jens@samuelsson.nu
[Wed Feb 08 20:54:26 2012] [error] [client 46.105.8.54] =========>> outbox: jens@samuelsson.nu
[Wed Feb 08 20:54:27 2012] [error] [client 46.105.8.54] =========>> outbox: jensyo@spray.se
[Wed Feb 08 20:54:27 2012] [error] [client 46.105.8.54] =========>> outbox: jensyo@spray.se
[Wed Feb 08 20:54:27 2012] [error] [client 46.105.8.54] =========>> outbox: jensyo@spray.se
[Wed Feb 08 20:54:28 2012] [error] [client 46.105.8.54] =========>> outbox: jentrempon@yahoo.fr
[Wed Feb 08 20:54:28 2012] [error] [client 46.105.8.54] =========>> outbox: jentrempon@yahoo.fr
[Wed Feb 08 20:54:28 2012] [error] [client 46.105.8.54] =========>> outbox: jentrempon@yahoo.fr

C'est donc un probleme qui se pose quand il y a un sleep au sein de la boucle.

Ca n'a rien a voir avec l'envoi du mail apparemment.

stephaneeybert
08/02/2012, 19h18
J'ai du nouveau ! Et du tres bizarre en plus..

En faisant des tests, j'ai pu me rendre compte que la fonction mail etait appellee plusieurs fois par destinataire.

Ca n'est donc pas un probleme de mail.

Mais un probleme de boucle.

Voici donc ou se trouve la chose curieuse.

C'est la boucle:

$mailOutboxes = $mailOutboxUtils->selectUnsent();

foreach ($mailOutboxes as $mailOutbox) {
$mailOutboxId = $mailOutbox->getId();
$firstname = $mailOutbox->getFirstname();
$lastname = $mailOutbox->getLastname();
$email = $mailOutbox->getEmail();
$strMetaNames = $mailOutbox->getMetaNames();

$firstname = LibString::escapeQuotes($firstname);
$lastname = LibString::escapeQuotes($lastname);

// Parse the meta names
$mailBody = $mailOutboxUtils->parseMetaNames($body, $mailOutboxId);

// Parse the custom meta names
// to replace in the mail body, meta names with specific values
// like an elearning subscription for example
$metaNames = $mailOutboxUtils->stringToMetaNames($strMetaNames);
if (count($metaNames) == 0 || $mailUtils->isCustomMetaNameCorrect($mailBody, $metaNames)) {
$mailBody = $mailOutboxUtils->parseCustomMetaName($mailBody, $metaNames);

if ($remainingMetaNames = $mailOutboxUtils->getRemainingMetaNames($mailBody)) {
$errorMessage = $mlText[1] . ' ' . $remainingMetaNames;
$mailOutbox->setErrorMessage($errorMessage);
$mailOutboxUtils->update($mailOutbox);
} else {
// Wait a bit before sending the email
// so as to avoid clogging the mail system
sleep(1);

// Send to the email addresses
LibEmail::sendMail($email, "$firstname $lastname", $subject, $mailBody, $senderEmail, $senderName, $attachedImages, $attachedFiles, $inTextFormat);

// Mark the email address as having been sent the email to
$mailOutbox->setSent(1);
$mailOutboxUtils->update($mailOutbox);
}
}
}

Curieux car ce code fonctionne bien depuis des annees sur un autre serveur, un petit serveur tout poussif et tout vieux d'ailleurs.

Or, sur mon serveur chez OVH, voila t'y pas que la boucle se comporte de la maniere la plus diabolique qui soit.

Au debut, pour les 1000 a 2000 premiers objets, elle se comporte normalement. Mais plus tard, vers les 3000 emes, elle se repete, et un object au lieu de passer une fois dans la boucle, va y passer 2 fois. Et ceci pour tous les objets suivants, qui eux aussi vont y passer 2 fois. Puis, encore plus tard, autour des 4000eme, un object va y passer 3 fois, et de meme pour les suivants. Et ainsi de suite, jusqu'a arriver vers les 5000eme ou les objects passent la 4 ou 5 fois chacun.

C'est comme si avec la fatigue, la boucle commencait a patiner, un peu, puis de plus en plus.

C'est vraiment tres etrange, comme organique.. flipant.. je me planque sous mon bureau..

La boucle est:

$mailOutboxes = $mailOutboxUtils->selectUnsent();

foreach ($mailOutboxes as $mailOutbox) {
...
}

Voila le sql:

function selectUnsent($start = false, $rows = false) {
$sqlStatement = "SELECT SQL_CALC_FOUND_ROWS * FROM $this->tableName WHERE sent != '1' ORDER BY email";
if ($rows) {
if (!$start) {
$start = 0;
}
$sqlStatement .= " LIMIT " . $start . ", " . $rows;
} else if ($start) {
$sqlStatement .= " LIMIT " . $start;
}
return($this->querySelect($sqlStatement));
}

stephaneeybert
01/02/2012, 17h36
Sinon, voila comment j'appelle le script sendBatch, a l'aide la la routine suivante:

Code:
  // Call a batch script to do the backup asynchronuously so as to avoid a time out of the script in the web browser
  function execlCLIwget($scriptFileUrl) {
    $procCommand = "wget \"$scriptFileUrl\" -q -O - -b";
    $proc = popen($procCommand, "r");
    pclose($proc);
  }
Ca pourrait venir de ce wget, l'envoi en plusieurs exemplaires ?

Le fichier script send.php qui fait cet appel par wget:

Code:
checkAdminModule(MODULE_MAIL);

$mlText = $languageUtils->getMlText(__FILE__);

$warnings = array();

$formSubmitted = LibEnv::getEnvHttpPOST("formSubmitted");

if ($formSubmitted) {

  $mailId = LibEnv::getEnvHttpPOST("mailId");
  $mailListId = LibEnv::getEnvHttpPOST("mailListId");
  $userId = LibEnv::getEnvHttpPOST("userId");
  $parentUrl = LibEnv::getEnvHttpPOST("parentUrl");
  $emailAddress = LibEnv::getEnvHttpPOST("emailAddress");
  $userRecipients = LibEnv::getEnvHttpPOST("userRecipients");
  $sendToAllFailed = LibEnv::getEnvHttpPOST("sendToAllFailed");
  $textFormat = LibEnv::getEnvHttpPOST("textFormat");
  $senderEmail = LibEnv::getEnvHttpPOST("senderEmail");
  $senderName = LibEnv::getEnvHttpPOST("senderName");

  $emailAddress = LibString::cleanString($emailAddress);
  $userRecipients = LibString::cleanString($userRecipients);
  $sendToAllFailed = LibString::cleanString($sendToAllFailed);
  $senderEmail = LibString::cleanString($senderEmail);
  $senderName = LibString::cleanString($senderName);

  $senderEmail = strtolower($senderEmail);
  if ($senderEmail && !LibEmail::validate($senderEmail)) {
    array_push($warnings, $mlText[39]);
  }

  $subject = '';
  $body = '';
  $attachments = '';
  if ($mail = $mailUtils->selectById($mailId)) {
    $subject = $mail->getSubject();
    $body = $mail->getBody();
    $attachments = $mail->getAttachments();
  }

  // Fix the body
  if ($body) {
    // Escape the quote slashes
    $body = LibString::escapeQuotes($body);
  }

  // The subject and the body are required
  if (!$subject || !$body) {
    array_push($warnings, $mlText[7]);
  }

  $websiteEmail = $profileUtils->getProfileValue("website.email");
  $websiteName = $profileUtils->getProfileValue("website.name");

  // This script can also act as a view controller for other scripts
  // In that case a list of recipients will already have been set
  // The mail recipients list is already set in the client script
  if (!isset($mailRecipients)) {
    $mailRecipients = array();
  }
  if (count($mailRecipients) == 0) {

    // Send to the failed email addresses of the last sending
    if ($sendToAllFailed) {
      $nbFailed = $mailOutboxUtils->countFailed();
      if ($nbFailed > 0) {
        $mailOutboxes = $mailOutboxUtils->selectUnsent();
        if (count($mailOutboxes) > 0) {
          foreach ($mailOutboxes as $mailOutbox) {
            $firstname = $mailOutbox->getFirstname();
            $lastname = $mailOutbox->getLastname();
            $email = $mailOutbox->getEmail();
            // Add the email to the list
            array_push($mailRecipients, array($email, $firstname, $lastname, '', ''));
          }
        }
      }
    } else if ($emailAddress) {
      // Send to one or several email addresses
      $emailAddress = LibString::trim($emailAddress);
      $severalAddresses = explode(' ', $emailAddress);

      foreach ($severalAddresses as $oneAddress) {
        if (!LibEmail::validate($oneAddress)) {
          array_push($warnings, $mlText[38]);
        }

        // The email is case insensitive
        $oneAddress = strtolower($oneAddress);

        // Add the email to the list
        array_push($mailRecipients, array($oneAddress, '', '', '', ''));
      }
    } else if ($mailListId) {
      // Send to a list of recipients

      $mailListAddresses = $mailListAddressUtils->selectByMailListId($mailListId);
      foreach ($mailListAddresses as $mailListAddress) {
        $mailAddressId = $mailListAddress->getMailAddressId();
        if ($mailAddress = $mailAddressUtils->selectById($mailAddressId)) {
          $email = $mailAddress->getEmail();
          $firstname = $mailAddress->getFirstname();
          $lastname = $mailAddress->getLastname();
          $subscribe = $mailAddress->getSubscribe();
          if ($email && $subscribe) {
            // Add the email to the list
            array_push($mailRecipients, array($email, $firstname, $lastname, '', ''));
          }
        }
      }

      $mailListUsers = $mailListUserUtils->selectByMailListId($mailListId);
      foreach ($mailListUsers as $mailListUser) {
        $userId = $mailListUser->getUserId();
        if ($user = $userUtils->selectById($userId)) {
          $firstname = $user->getFirstname();
          $lastname = $user->getLastname();
          $email = $user->getEmail();
          $password = $user->getReadablePassword();
          $subscribe = $user->getMailSubscribe();
          if ($email && $subscribe) {
            // Add the email to the list
            array_push($mailRecipients, array($email, $firstname, $lastname, $password, ''));
          }
        }
      }
    } else if ($userId) {
      // Send to a user
      if ($user = $userUtils->selectById($userId)) {
        $firstname = $user->getFirstname();
        $lastname = $user->getLastname();
        $email = $user->getEmail();
        $password = $user->getReadablePassword();
        $subscribe = $user->getMailSubscribe();
        if ($email && $subscribe) {
          // Add the email to the list
          array_push($mailRecipients, array($email, $firstname, $lastname, $password, ''));
        }
      }
    } else if ($userRecipients != '') {
      $systemDate = $clockUtils->getSystemDate();
      if ($userRecipients == 'user_recipient_expired') {
        $users = $userUtils->selectExpiredMailSubscribers($systemDate);
      } else if ($userRecipients == 'user_recipient_current') {
        $users = $userUtils->selectCurrentMailSubscribers($systemDate);
      } else if ($userRecipients == 'user_recipient_all') {
        $users = $userUtils->selectAllMailSubscribers();
      }

      if (count($users) > 0) {
        foreach ($users as $user) {
          $userId = $user->getId();
          $email = $user->getEmail();
          $password = $user->getReadablePassword();
          $firstname = $user->getFirstname();
          $lastname = $user->getLastname();
          $subscribe = $user->getMailSubscribe();

          if ($subscribe) {
            if (LibEmail::validate($email)) {
              // Add the email to the list
              array_push($mailRecipients, array($email, $firstname, $lastname, $password, ''));
            }
          }
        }
      }
    } else if ($sendToAllFailed) {
      $nbFailed = $mailOutboxUtils->countFailed();
      if ($nbFailed > 0) {
        $mailOutboxes = $mailOutboxUtils->selectUnsent();
        if (count($mailOutboxes) > 0) {
          foreach ($mailOutboxes as $mailOutbox) {
            $firstname = $mailOutbox->getFirstname();
            $lastname = $mailOutbox->getLastname();
            $email = $mailOutbox->getEmail();
            // Add the email to the list
            array_push($mailRecipients, array($email, $firstname, $lastname, '', ''));
          }
        }
      }
    }

  }

  // Check that there are some email addresses
  if (count($mailRecipients) == 0) {
    array_push($warnings, $mlText[5]);
  }

  if (count($warnings) == 0) {

    // Get the date and time the email has been sent
    $sendDateTime = $clockUtils->getSystemDateTime();

    if ($mail = $mailUtils->selectById($mailId)) {
      // Update the mail subject and format if changed
      $mail->setSubject($subject);
      $mail->setTextFormat($textFormat);

      // Update the last send date
      $mail->setSendDate($sendDateTime);

      $mailUtils->update($mail);
    }

    // Empty the outbox previous list of email addresses
    $mailOutboxUtils->deleteAll();

    // Activate a semaphore to tell a mailing is ongoing
    $mailOutboxUtils->mailingOngoing();

    // Store the list of email addresses in the outbox
    // for later use by the mail batch script
    // Some meta names and their values can be specified
    // to replace in the mail body, meta names with specific values
    // like an elearning subscription for example
    foreach ($mailRecipients as $mailRecipient) {
      list($email, $firstname, $lastname, $password, $metaNames) = $mailRecipient;
      $firstname = LibString::escapeQuotes($firstname);
      $lastname = LibString::escapeQuotes($lastname);
      $strMetaNames = $mailOutboxUtils->metaNamesToString($metaNames);
      $mailOutbox = new MailOutbox();
      $mailOutbox->setFirstname($firstname);
      $mailOutbox->setLastname($lastname);
      $mailOutbox->setEmail($email);
      $mailOutbox->setPassword($password);
      $mailOutbox->setMetaNames($strMetaNames);
      $mailOutboxUtils->insert($mailOutbox);
    }

    $scriptFile = $gMailUrl . "/sendBatch.php?mailId=$mailId&senderEmail=$senderEmail&senderName=$senderName";
    $commonUtils->execlCLIwget($scriptFile);

    // Register the email sending in the history
    $adminId = $adminUtils->getLoggedAdminId();
    $mailHistory = new MailHistory();
    $mailHistory->setSubject($subject);
    $mailHistory->setBody($body);
    $mailHistory->setAttachments($attachments);
    $mailHistory->setMailListId($mailListId);
    $mailHistory->setEmail($emailAddress);
    $mailHistory->setAdminId($adminId);
    $mailHistory->setSendDate($sendDateTime);
    $mailHistoryUtils->insert($mailHistory);

    // Reset the session value for the result display
    LibSession::putSessionValue(MAIL_SESSION_STATUS, '');

    $str = LibHtml::urlRedirect($parentUrl);
    printContent($str);
    return;

  }

}

$mailId = LibEnv::getEnvHttpGET("mailId");
if (!$mailId) {
  $mailId = LibEnv::getEnvHttpPOST("mailId");
}

$mailListId = LibEnv::getEnvHttpGET("mailListId");
if (!$mailListId) {
  $mailListId = LibEnv::getEnvHttpPOST("mailListId");
}

$userId = LibEnv::getEnvHttpGET("userId");
if (!$userId) {
  $userId = LibEnv::getEnvHttpPOST("userId");
}

$emailAddress = '';
$subject = '';
$textFormat = '';
if ($mail = $mailUtils->selectById($mailId)) {
  $subject = $mailUtils->renderSubject($mail);
  // The subject string must be cleaned up
  $subject = LibString::cleanString($subject);
  $textFormat = $mail->getTextFormat();
}

$mailListName = '';
if ($mailList = $mailListUtils->selectById($mailListId)) {
  $mailListName = $mailList->getName();
}

$userName = '';
if ($user = $userUtils->selectById($userId)) {
  $userName = $user->getFirstname() . ' ' . $user->getLastname();
}

if ($textFormat == '1') {
  $checkedTextFormat = "CHECKED";
} else {
  $checkedTextFormat = '';
}

// The url to the parent menu can already be set in another script
if (!isset($parentUrl)) {
  $parentUrl = "$gMailUrl/admin.php";
}

$strWarning = '';
if (count($warnings) > 0) {
  foreach ($warnings as $warning) {
    $strWarning .= "
$warning"; } } $panelUtils->setHeader($mlText[0], $parentUrl); $help = $popupUtils->getHelpPopup($mlText[9], 300, 400); $panelUtils->setHelp($help); // Check if some mails failed in the previous sending $nbFailed = $mailOutboxUtils->countFailed(); // Display a warning if the last sending had some failed sendings if ($nbFailed > 0) { $panelUtils->addLine('', $panelUtils->addCell($mlText[25], "w")); $panelUtils->addLine(); } // Check that no other mail is being sent // Avoid concurrent access to the mass mailing $ongoing = $mailOutboxUtils->isMailingOnGoing(); if ($ongoing) { $panelUtils->addLine('', $panelUtils->addCell($mlText[22], "w")); $panelUtils->addLine(); } $userRecipients = Array('' => '', 'user_recipient_expired' => $mlText[14], 'user_recipient_current' => $mlText[17], 'user_recipient_all' => $mlText[19]); $strSelectUserRecipient = LibHtml::getSelectList("userRecipients", $userRecipients); $panelUtils->addLine($panelUtils->addCell($strWarning, "wb")); $panelUtils->openForm($PHP_SELF, "edit"); $strJsSuggest = $commonUtils->ajaxAutocomplete("$gMailUrl/suggestMails.php", "subject", "mailId"); $panelUtils->addContent($strJsSuggest); $panelUtils->addHiddenField('mailId', $mailId); $label = $popupUtils->getTipPopup($mlText[20], $mlText[21], 300, 100); $panelUtils->addLine($panelUtils->addCell($label, "nbr"), ""); if ($mailId) { $strBody = $popupUtils->getDialogPopup(" $mlText[3]", "$gMailUrl/preview.php?mailId=$mailId", 600, 600); $strAttachment = $popupUtils->getDialogPopup(" $mlText[18]", "$gMailUrl/attachment/admin.php?mailId=$mailId", 600, 600); $panelUtils->addLine('', "$strBody $strAttachment"); } $panelUtils->addLine(); // This script can also act as a view controller for other client scripts // In that case a list of recipients will already have been set if (!isset($strImposedSelectList)) { $strJsSuggest = $commonUtils->ajaxAutocomplete("$gMailUrl/list/suggestLists.php", "mailListName", "mailListId"); $panelUtils->addContent($strJsSuggest); $panelUtils->addHiddenField('mailListId', $mailListId); $label = $popupUtils->getTipPopup($mlText[6], $mlText[12], 300, 200); $panelUtils->addLine($panelUtils->addCell($label, "nbr"), ""); $panelUtils->addLine(); $strJsSuggest = $commonUtils->ajaxAutocomplete("$gUserUrl/suggestUsers.php?subscribe=1", "userName", "userId"); $panelUtils->addContent($strJsSuggest); $panelUtils->addHiddenField('userId', $userId); $label = $popupUtils->getTipPopup($mlText[23], $mlText[24], 300, 200); $panelUtils->addLine($panelUtils->addCell($label, "nbr"), ""); $panelUtils->addLine(); $label = $popupUtils->getTipPopup($mlText[8], $mlText[11], 300, 400); $panelUtils->addLine($panelUtils->addCell($label, "br"), ""); $panelUtils->addLine(); $label = $popupUtils->getTipPopup($mlText[10], $mlText[13], 300, 200); $panelUtils->addLine($panelUtils->addCell($label, "br"), $strSelectUserRecipient); } else { $label = $popupUtils->getTipPopup($mlText[6], $mlText[12], 300, 200); $panelUtils->addLine($panelUtils->addCell($label, "br"), $strImposedSelectList); $panelUtils->addContent($strHiddenPost); } $panelUtils->addLine(); // Add the list of failed sendings if any if ($nbFailed > 0) { $label = $popupUtils->getTipPopup($mlText[26], $mlText[27], 300, 300); $panelUtils->addLine($panelUtils->addCell($label, "wbr"), $panelUtils->addCell(" $mlText[28]", "w")); $panelUtils->addLine(); } if (!isset($senderEmail)) { $senderEmail = $profileUtils->getProfileValue("website.email"); $senderName = $profileUtils->getProfileValue("website.name"); } $label = $popupUtils->getTipPopup($mlText[40], $mlText[41], 300, 400); $panelUtils->addLine($panelUtils->addCell($label, "br"), " "); $panelUtils->addLine(); $label = $popupUtils->getTipPopup($mlText[15], $mlText[16], 300, 300); $panelUtils->addLine($panelUtils->addCell($label, "rb"), ""); $panelUtils->addLine(); $panelUtils->addLine($panelUtils->addCell($mlText[2], "br"), $panelUtils->getOk()); $panelUtils->addHiddenField('formSubmitted', 1); $panelUtils->addHiddenField('parentUrl', $parentUrl); $panelUtils->closeForm(); $str = $panelUtils->render(); printAdminPage($str); ?>

stephaneeybert
01/02/2012, 17h22
Pour l'encodage du sujet du mail, voila ce que j'avais avant ta remarque:

// The subject must not contain html encoded characters
$subject = html_entity_decode($subject, ENT_QUOTES);

Et voila ce que j'ai mis maintenant:

// The subject must not contain html encoded characters
$subject = html_entity_decode($subject, ENT_QUOTES);

// The subject must be encoded
$subject = utf8_encode($subject);

Je viens de m'envoyer un mail avec les lettres å ø æ dans le sujet et je l'ai bien recu, les lettres s'affichent bien.

Le header affiche lui:

Subject:

C'est le bon encodage ca ?

stephaneeybert
01/02/2012, 13h39
J'ai ajoute hier un error_log dans la routine d'envoi de mail.

La prochaine fois j'en saurai un peu plus.

fritz2cat
01/02/2012, 11h18
Heu. Je ne sais pas

Frédéric

stephaneeybert
01/02/2012, 06h56
Je serais quand meme vachement surpris que ma routine mail soit appellee 4 fois par destinataire. La premiere incidence du probleme, c'etait d'ailleurs 5 fois par destinataire. Elle marche bien depuis pas mal de temps deja, quelques annees, notement sur un autre serveur dedie chez sivit.fr avant que je ne demenage chez OVH ce mois ci. La routine est appellee par un fichier batch, c'est peut-etre que le batch est lui execute plusieurs fois ? Le probleme ne s'est jamais produit chez sivit.fr et il ne se produit pas chez OVH sur d'autres listes de destinataires plus modestes qui ont autour de 500 destinataires, pour le meme site web et un autre site web, tous deux sur le meme serveur et meme applicatif.

Voila le fichier batch:
Code:
getMlText(__FILE__);

if (!$senderEmail) {
  $senderEmail = $profileUtils->getProfileValue("website.email");
  $senderName = $profileUtils->getProfileValue("website.name");
}

// Get the subject and the body
$subject = '';
$body = '';
$attachedFiles = array();;
if ($mail = $mailUtils->selectById($mailId)) {
  $subject = $mailUtils->renderSubject($mail);
  $body = $mailUtils->renderBody($mail);
  $attachedFiles = $mailUtils->getExistingAttachedFiles($mailId, true);
}

// The subject and the body are required
if (!$subject || !$body) {
  reportError($mlText[0]);
}

// Check if the mail is to be sent in a text format
if ($mailUtils->inTextFormat($mailId)) {
  $inTextFormat = true;
} else {
  $inTextFormat = false;
}

// Create the array and transform the image tags in the body
$attachedImages = array();
if (!$inTextFormat) {
  // Transform the image urls into email image elements
  $body = $mailUtils->urlToEmailImageCID($body);
  $attachedImages = $mailUtils->getImagesFromCID($body);

  // Transform the links urls from relative to absolute
  $body = $mailUtils->relativeToAbsoluteUrls($body);

  // Add the user email address to a unsubscribe page url if any
  $body = $mailUtils->addEmailAddressToUnsubscribeUrl($body);

  // Add the user login name and password to a login page link if any
  $body = $mailUtils->addLoginPasswordToLoginUrl($body);
}

$mailOutboxes = $mailOutboxUtils->selectUnsent();

foreach ($mailOutboxes as $mailOutbox) {
  $mailOutboxId = $mailOutbox->getId();
  $firstname = $mailOutbox->getFirstname();
  $lastname = $mailOutbox->getLastname();
  $email = $mailOutbox->getEmail();
  $strMetaNames = $mailOutbox->getMetaNames();

  $firstname = LibString::escapeQuotes($firstname);
  $lastname = LibString::escapeQuotes($lastname);

  // Parse the meta names
  $mailBody = $mailOutboxUtils->parseMetaNames($body, $mailOutboxId);

  // Parse the custom meta names
  // to replace in the mail body, meta names with specific values
  // like an elearning subscription for example
  $metaNames = $mailOutboxUtils->stringToMetaNames($strMetaNames);
  if (count($metaNames) == 0 || $mailUtils->isCustomMetaNameCorrect($mailBody, $metaNames)) {
    $mailBody = $mailOutboxUtils->parseCustomMetaName($mailBody, $metaNames);

    if ($remainingMetaNames = $mailOutboxUtils->getRemainingMetaNames($mailBody)) {
      $errorMessage = $mlText[1] . ' ' . $remainingMetaNames;
      $mailOutbox->setErrorMessage($errorMessage);
      $mailOutboxUtils->update($mailOutbox);
    } else {
      // Wait a bit before sending the email
      // so as to avoid clogging the mail system
      sleep(1);

      // Send to the email addresses
      LibEmail::sendMail($email, "$firstname $lastname", $subject, $mailBody, $senderEmail, $senderName, $attachedImages, $attachedFiles, $inTextFormat);

      // Mark the email address as having been sent the email to
      $mailOutbox->setSent(1);
      $mailOutboxUtils->update($mailOutbox);
    }
  }
}

// Activate a semaphore to tell the mailing has ended
$mailOutboxUtils->mailingEnded();

?>

fritz2cat
01/02/2012, 06h51
Non, juste pour savoir combien d'appels tu fais à mail()

F.

stephaneeybert
01/02/2012, 06h49
Tu parles d'un logging dans une log commune, et ce pour des vps ou dedies differents qui loggeraient sur la meme log ? Dans quel but ? C'est OVH qui veut savoir qui envoi des mails ? Ou le poliburo ? :-)

fritz2cat
01/02/2012, 06h41
Bon on s'égare... et c'est un peu de ma faute...

Il y a deux ou trois semaines, il y a eu un post dans le forum concernant un logging de tous les appels à mail() pour tracer qui (ou quel site) envoyait des mails.
Il va falloir chercher un peu.
Ca consistait à remplacer l'appel à sendmail par un script, ceci dans php.ini, si je me rappelle bien. Il y avait aussi le script en question.

Frédéric

stephaneeybert
31/01/2012, 21h25
C'etait avec un suisse divemaster, Philippe Yersin, qui faisait du padi, on descendait de Paris pour une semaine a chaque fois, on etait a l'hotel au dessus du port, c'est vrai que ca avait l'air un peu different de la formation francaise..

fritz2cat
31/01/2012, 20h58
Galeria ? Padi ? quand j'y suis allé c'était du pur jus FFESSM...
A mon avis, Nicolas et Jo n'ont pas l'étiquette Padi

Frédéric, Bruxelles, Lifras, 3*

stephaneeybert
31/01/2012, 20h48
Aie ! Elle est bien froide.. En ce moment il fait -10 dehors.

J'ai plonge en Corse pour mon niveau Padi.. a Galeria, cool la Corse !

fritz2cat
31/01/2012, 20h22
Citation Envoyé par stephaneeybert
Si tu viens a Tallinn n'hesite pas :-)
Quelle est la température de l'eau ? Il y a des clubs de plongée ?

Frédéric

stephaneeybert
31/01/2012, 20h11
Bon, je vais me pencher sur cette routine, etrange car elle marche bien pour d'autres listes de destinataires.. A moins que la liste de 3000 destinataires en contiennent de nombreux en plusieurs exemplaires..

Pour l'encodage du sujet, tu connais une fonction php qui fait ca ?

La fonction utf8_encode ferait l'affaire ?

Merci encore pour ton travail !

Si tu viens a Tallinn n'hesite pas :-)

fritz2cat
31/01/2012, 19h36
Bonsoir

Finalement les message-id étaient complets
Message-ID: <20120131110808.12932.qmail@vps13495.ovh.net>
Ils ont été ajoutés pas qmail.

Je suis à 99,9% certain que ton script PHP envoie plusieurs fois chaque message.

Attention, tes e-mails violent les protocoles.
Un subject: tel que "Föredrag på lätt franska" ou "Några platser kvar! Déjeuner - débat du lundi 6 février à 11h30" doit être encodé.
ö, å, ä, é, à ne peuvent pas apparaître.
Regarde comment Outlook ou Thunderbird convertiraient ce sujet.
Subject: =?iso-8859-1?Q?F=F6redrag_p=E5_l=E4tt_franska?=
Frédéric

stephaneeybert
31/01/2012, 18h17
Voila donc un mail en entier avec les headers, c'est mon adresse email a moi, je suis un des recipients de la liste de destinataires.

From Europasprak Tue Jan 31 11:08:08 2012
X-Apparently-To: mittiprovence@yahoo.se via 188.125.83.142; Tue, 31 Jan 2012 11:09:05 +0000
Return-Path:
Received-SPF: none (domain of thalasoft.com does not designate permitted sender hosts)
aGVscG5zPiA8L3NwYW4.S2xpY2thIGgmYXVtbDtyPj48L3NwYW 4.PC9hPgoK
CQoKCTwvc3Bhbj4KCgkKCgkgCgoJCgoJQm9uam91ciA8L3NwYW 4.PC9zcGFu
PlN0ZXBoYW5lPC9zcGFuPjwvc3Bhbj48L3NwYW4.CgoJCgoJCg oJTHVuZGkg
NiBmJmVhY3V0ZTt2cmllciwgZCZlYWN1dGU7amV1bmVyIGVuIG ZyYW4mY2Nl
ZGlsO2FpcyBzdXIgbGUgdGgmZWdyYXZlO21lIDo8L3htbG5zOn RleHRoZWxw
bnM.ATABAQEBZnJhbnNrYXBhbHVuY2hlbi5qcGcDaW1hZ2UvcG 5nAwMzNwJE
UkFQRUFVX1NVSVNTRTIxLmdpZgNpbWFnZS9wbmcDAzQCTmFnbG 8yMi5naWYD
aW1hZ2UvcG5nAwMxNwJMb2dvRVNNb2IuanBnA2ltYWdlL3BuZw MDNDE-
X-YMailISG: CYXBXAUWLDtd6I7KRoDad5Tll.w.zqgnwVicjuhM4HWSb5iR
94yKTfX_tJL.M9mbUkPJgE_OVxK9lcMXK17zRLtYiXJjEIF1Iq FiVtVJ_8Ad
z0fkSLC5svFBCeLcYSmKplQlPGph7ntzIz629mS0b18lU_LJ7f 15R2mxAPMG
ibcgDlla7GNV_Q9bkNCbYC9LgWxIJvyIb2StmGSJ2uhB.0ATm8 g.DsU5on.o
ofdKW976PrnJ.QDtQO.hwYYZ5vKa6Jc9AgF.SknHKG_ZHZSAOa k6M7KEywbd
rbeY8C5uWggnSUQYhDHzkVVJAXa3bE3fZeKqhkOPRFT72rX18q VMQRD8oFua
UbCKPNqrn9GKZmcD9Ixgngoi54jOHaWVUBwb0RYxovkld31ISY Az3eU0uZtL
UeH.YadQ_s17GojejCq01pWfuf9cWHMpYg.e2ezaW6yz9bzhZv oWTr1USWmB
zje6GeB0UbZB1ss6n0.JWLbPutdv6IWMt0HEw2o29Grwg_9Yrd od1eHkRpYg
aEeRm6LY932eK._gWuhrniv8e0.gCEDOn2KmbC7fGwTXTnfvVR v26KTbPZ4T
Bku_rmZVQjfNbu8aGWHg.PCZJCWn6wAO8dO2pYVUpuRQFzjF2L w1.4UP0gXA
W1V_oyyk.m_VpG_o9DtVHdkp3YlG0_0J6guFDDH9ejeIcG3qhz Mfh9cRogah
9p.1jFgXCsiwKtG8rmCr73_nQRKPllLNCzRKRZKsYtsoTFFaRL AC.vsMLGuy
TBfGM2Ur4zqdBSe5kbtIfZh6UJ6YW5qMFKhIwRJsI9Qy4.RVG6 eMH7.dvwx.
PyS86RWU4Vw1ARcGrJpjwmxcrJfxOtROpCx4Bd2ZKqvitY0jJn L2eWmIyXfg
NUMBuoC29LMr2vn2xW_IsIEYeidyR8d8WJ5xdCmmq.faz7HkEW B1FA5NM6O9
MpIeF_MRL25S
X-Originating-IP: [46.105.8.54]
Authentication-Results: mta1011.mail.ukl.yahoo.com from=europasprak.com; domainkeys=neutral (no sig); from=europasprak.com; dkim=neutral (no sig)
Received: from 127.0.0.1 (EHLO vps13495.ovh.net) (46.105.8.54)
by mta1011.mail.ukl.yahoo.com with SMTP; Tue, 31 Jan 2012 11:09:05 +0000
Received: (qmail 12936 invoked by uid 1002); 31 Jan 2012 11:08:08 -0000
Message-ID: <20120131110808.12932.qmail@vps13495.ovh.net>
To: Stephane Eybert
Subject: Ngra platser kvar! Djeuner - dbat du lundi 6 fvrier 11h30
X-PHP-Originating-Script: 1002:email.php
From: Europasprak
Reply-To: Europasprak
X-Confirm-Reading-To: Europasprak
Return-Receipt-To: Europasprak
Errors-To: Europasprak
X-Sender: http://www.europasprak.com
X-Mailer: PHP(46.105.8.54)
X-auth-smtp-user: christophe.luciani@europasprak.com
X-abuse-contact: Bounce Error
Date: Tue, 31 Jan 2012 11:08:08 +0000
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_205ea551fd84aa1f900c389af4d3bdc3"
Content-Length: 112469
Et aussi l'en-tete d'un autre email (un des 4 que j'ai recu a la suite)

From Europasprak Tue Jan 31 11:08:08 2012
X-Apparently-To: mittiprovence@yahoo.se via 188.125.83.145; Tue, 31 Jan 2012 11:09:05 +0000
Return-Path:
Received-SPF: none (domain of thalasoft.com does not designate permitted sender hosts)
bWw7cj4.CgoJCgoJCgoJCgoJIAoKCQoKCUJvbmpvdXIgU3RlcG hhbmUKCgkK
CgkKCglMdW5kaSA2IGYmZWFjdXRlO3ZyaWVyLCBkJmVhY3V0ZT tqZXVuZXIg
ZW4gZnJhbiZjY2VkaWw7YWlzIHN1ciBsZSB0aCZlZ3JhdmU7bW UgOgoKCQoK
CSJMYSBTdWlzc2UgISIKCgkKCgkgIAoKCQoKCUV1cm9wYXNwci ZhcmluZztr
IGkgc2FtYXJiZXRlIG1lZCBMRSBGUkFOQ09GSUwnIGFub3Jkbm FyATABAQEB
ZnJhbnNrYXBhbHVuY2hlbi5qcGcDaW1hZ2UvcG5nAwMzNwJEUk FQRUFVX1NV
SVNTRTIxLmdpZgNpbWFnZS9wbmcDAzQCTmFnbG8yMi5naWYDaW 1hZ2UvcG5n
AwMxNwJMb2dvRVNNb2IuanBnA2ltYWdlL3BuZwMDNDE-
X-YMailISG: Sx6zotwWLDtXx.44jb3OANve33jCU2VNXeCscgpL0mSkTETL
q3qXay9naWQhxuYWkvfAyMWL9RYU2cGxwLkwq3e.PtOL1iqVts MamqIZM_3I
V5X44rf0epHo8IvLDzcJrnNeLue4rE33YVUDTmg10NlTiief_t 3pKZNLg3MA
jCV971xsP0IanDk52Ti5xOV5.Wl9U25bpHSjf1Z8dUVwUe828U KqZzkxgrnw
dt3OgM4AiQMYAmIgRUwKmp8Gh4COeHKwnIo2nhZ.tuuuz39lGv Z0my0UfQ1s
aOQn.3hZgq4BAPCcaD.xi9rRUWu01nZWGSvwPbBrRUNU8QtOnJ Cj9cAWWwKJ
WBnear29pLA.kz2Q_lnno2A_wXG0AJgkCIzKmJ1a4K4I23mKSM 9lFR87IujL
s2FKHJs0k9ACmAwBnsvKDXTKtoqC66sg_0NlC5uYkNjM_RRqIe ZrUkSmuwIf
KGKqm3ocuR8UZ2c8gEzFDgl5KkoXrf9M1RSCqdJncAXTo6E5xJ 4Oug7zA3c5
TAvRtv2tCB8WrIM004dM.xnc160SuDNy7qRkEhckT6EKgjmh7W BlcxIPetTE
6oXgk3uODGWeWHE17umYNqK1oiezH7rzXUrCNmH0oj0auGzPER jhrDnRDL4W
3.CLfpDnY3ABG87xuv6UnviE0tpfZv7ulT7qp3fUtsGGNScCeU P.YfETEUNa
HVlWcxazQI4nCXkeMxLwj137jNGVvOzdC7NG4rxELSWo2UXnv5 V8l4wc3pzr
iGl9i_7kIV3yRoNOQ6mEweQMVZXkHKZSUxoBm2XAeK1C8vMGRr qJCoq1q_Tq
BLSvFxuJ6qOXmNalmTGBg2kcl8M7yQMMpJcMGZvRhND4V2JQIi Jxe744iUpy
G4lt66aZ27XPr.IvYEl2bRTqp3p2j6yDqkwBwx340JF1T6Ql62 I8OxK2tR5U
NLukyuguqCtTSJROFbc5_MsyLxau3WAw22p0OEy5qeEaWqjHCj n1.23ZtaAR
5CEGm6I6dyFZqNWrgUZzagkrbh_xh7sQWj4z4e9M4o2iqDhJAa fQP.01fB5l
VdBa_hgkzseg1CUp69x_v0PCK6brFCrb_1.A_7ULvuwioxY.Qz giSc7Io6V0
bD6.G4gFfI0nKxOFrnf2s6ArXvJvfw--
X-Originating-IP: [46.105.8.54]
Authentication-Results: mta1059.mail.ukl.yahoo.com from=europasprak.com; domainkeys=neutral (no sig); from=europasprak.com; dkim=neutral (no sig)
Received: from 127.0.0.1 (EHLO vps13495.ovh.net) (46.105.8.54)
by mta1059.mail.ukl.yahoo.com with SMTP; Tue, 31 Jan 2012 11:09:05 +0000
Received: (qmail 12935 invoked by uid 1002); 31 Jan 2012 11:08:08 -0000
Message-ID: <20120131110808.12931.qmail@vps13495.ovh.net>
To: Stephane Eybert
Subject: Ngra platser kvar! Djeuner - dbat du lundi 6 fvrier 11h30
X-PHP-Originating-Script: 1002:email.php
From: Europasprak
Reply-To: Europasprak
X-Confirm-Reading-To: Europasprak
Return-Receipt-To: Europasprak
Errors-To: Europasprak
X-Sender: http://www.europasprak.com
X-Mailer: PHP(46.105.8.54)
X-auth-smtp-user: christophe.luciani@europasprak.com
X-abuse-contact: Bounce Error
Date: Tue, 31 Jan 2012 11:08:08 +0000
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_3479a002a2af32e7ab27b167ed8cedad"
Content-Length: 112469
Merci !

fritz2cat
31/01/2012, 16h07
J'ai l'impression que ta liste de destinataires contient sans doute beaucoup d'erreurs.
koopi.se ça vient de l'adresse mail injoignable lisa.jonsson@koopi.se

Peux-tu publier un mail entier reçu à partir de ton site, avec ses en-têtes SMTP, en masquant juste une partie des adresses e-mail, et rien que cela ? (exemple: remplacer prenom.nom@gmail.com par xxxxx@gmail.com (mais pas par xxxx@xxxx.xx)


Frédéric

stephaneeybert
31/01/2012, 15h42
Merci Frederic pour ton premier diagnostic. Je n'ai pas tes competences..

1- C'est quoi koopi.se ?

2- Je n'ai jamais entendu parler de message id avant ce probleme de mail repetes. Et je ne pense pas que ma routine d'envoi de mails en specifie un.

C'est une routine que j'ai cree et que j'appelle une fois pour chaque destinataire.

Pour un mailing de 3000 destinataires, elle est appelle 3000 fois, avec une pause de 1s entre chaque appel.

Voila la routine:

Code:
  // Send an email
  static function sendMail($toEmail, $toName, $subject, $body, $fromEmail = '', $fromName = '', $attachedImages = '', $attachedFiles = '', $textFormat = false) {

    // The subject must not contain html encoded characters
    $subject = html_entity_decode($subject, ENT_QUOTES);

    // The email is case insensitive
    $toEmail = strtolower($toEmail);
    $fromEmail = strtolower($fromEmail);

    // Do not send the mail if on my local server
    if (isset($_SERVER["SCRIPT_FILENAME"])) {
      $SCRIPT_FILENAME = $_SERVER["SCRIPT_FILENAME"];
    } else {
      $SCRIPT_FILENAME = '';
    }

    if (strstr($SCRIPT_FILENAME, "/home/stephane/dev")) {
      return(false);
    }

    if (!$toEmail || !LibEmail::validate($toEmail)) {
      return(false);
    }

    if ($fromEmail && !$fromName) {
      $fromName = $fromEmail;
    }

    // Create a fallback text formatted message for the email clients that do
    // not support html messages
    $textMessage = LibString::br2nl($body);
    $textMessage = LibString::p2nl($textMessage);
    $textMessage = LibString::stripTags($textMessage);
    $textMessage = LibString::normalizeLinebreaks($textMessage);
    $textMessage = str_replace(" ", '', $textMessage);
    $textMessage = preg_replace("/\t+/iU", '', $textMessage);
    $textMessage = preg_replace("/\n +/iU", "\n", $textMessage);
    $textMessage = preg_replace("/\n{2,}/iU", "\n\n", $textMessage);
    $textMessage = nl2br($textMessage);

    // The email can be sent in an html format or in a text format
    if ($textFormat) {
      $htmlErrorMessage = $textMessage;
    } else {
      $htmlErrorMessage = $body;
    }

    // Make sure the attachment is an array
    if ($attachedImages && !is_array($attachedImages)) {
      $attachedImages = array($attachedImages);
    }
    if ($attachedFiles && !is_array($attachedFiles)) {
      $attachedFiles = array($attachedFiles);
    }

    LibEmail::mail($fromName, $fromEmail, $toName, $toEmail, $subject, $htmlErrorMessage, $textMessage, $attachedImages, $attachedFiles);
  }

  static function mail($from_name, $from_email, $to_name, $to_email, $subject, $html_message, $text_message, $attachedImages, $attachedFiles) {
    global $REMOTE_ADDR;
    global $gHomeUrl;

    $from = "$from_name <$from_email>";
    $to   = "$to_name <$to_email>";
    $bounce_email = 'error@thalasoft.com';
    $bounce_name = 'Bounce Error';
    $bounce = "$bounce_name <$bounce_email>";

    // The text_message is displayed only if the html_message cannot be displayed
    // The text_message is a fallback message for those email clients that do not support html
    // messages
    // If the email client supports html messages and the html_message is empty then no message
    // will be displayed, that is, the text_message fallback message will not be displayed
    // To force the display of a text formatted message, store the message in the html_message
    if (!$html_message && $text_message) {
      $html_message = $text_message;
    }

    $main_boundary = "----=_NextPart_".md5(rand());
    $text_boundary = "----=_NextPart_".md5(rand());
    $html_boundary = "----=_NextPart_".md5(rand());

    $headers  = "From: $from\n";
    $headers .= "Reply-To: $from\n";
    $headers .= "Return-Path: $bounce\n";
// TODO THe next line was commented out because the recipient receives when opening his
// email to read it, is asked to confirm the reception or to ignore it, which is anoying for 
// the reciepient
//    $headers .= "Disposition-Notification-To: $bounce\n";
    $headers .= "X-Confirm-Reading-To: $from\n";
    $headers .= "Return-Receipt-To: $from\n";
    $headers .= "Errors-To: $from\n";

    $headers .= "X-Sender: $gHomeUrl\n";
    $headers .= "X-Mailer: PHP($REMOTE_ADDR)\n";
    $headers .= "X-auth-smtp-user: $from_email\n";
    $headers .= "X-abuse-contact: $bounce\n";

    $headers .= "Date: ". date('r') ."\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n";

    $message  = "\n--$main_boundary\n";
    $message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
    $message .= "\n--$text_boundary\n";
    $message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= ($text_message!="")?"$text_message":"Text portion of HTML Email";
    $message .= "\n--$text_boundary\n";
    $message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n";
    $message .= "\n--$html_boundary\n";
    $message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
    $message .= str_replace("=", "=3D", $html_message)."\n";

    // If the email has an html format and the attached file is an image
    // referenced in the email content then display it inline
    // otherwise display it as an attached file
    if (isset($attachedImages) && $attachedImages != '' && count($attachedImages) >= 1) {
      for ($i = 0; $i < count($attachedImages); $i++) {
        $attachedImage = $attachedImages[$i];
        $imageName = basename($attachedImage);
        if (is_file($attachedImage) && $html_message && LibImage::isImage($attachedImage) && strstr($html_message, $imageName)) {
          $fp = fopen ($attachedImage, "r");
          $fcontent = '';
          while (!feof ($fp)) {
            $fcontent .= fgets ($fp, 1024);
          }
          $fcontent = chunk_split (base64_encode($fcontent));
          fclose ($fp);
          $message .= "\n--$html_boundary\n";
          $message .= "Content-Type: image/png; name=\"$imageName\"\n";
          $message .= "Content-Transfer-Encoding: base64\n";
          $message .= "Content-Disposition: inline; filename=\"$imageName\"\n";
          $message .= "Content-ID: <$imageName>\n\n";
          $message .= $fcontent;
        }
      }
    }

    if (isset($attachedFiles) && $attachedFiles != '' && count($attachedFiles) >= 1) {
      for ($i = 0; $i < count($attachedFiles); $i++) {
        $attachedFile = $attachedFiles[$i];
        if (is_file($attachedFile)) {
          $fileName = basename($attachedFile);
          $fp = fopen ($attachedFile, "r");
          $fcontent = '';
          while (!feof ($fp)) {
            $fcontent .= fgets ($fp, 1024);
          }
          $fcontent = chunk_split (base64_encode($fcontent));
          fclose ($fp);
          $message .= "\n--$html_boundary\n";
          $message .= "Content-Type: application/octetstream\n";
          $message .= "Content-Transfer-Encoding: base64\n";
          $message .= "Content-Disposition: attachment; filename=\"$fileName\"\n";
          $message .= "Content-ID: <$fileName>\n\n";
          $message .= $fcontent;
        }
      }
    }

    $message .= "\n--$html_boundary--\n";
    $message .= "\n--$text_boundary--\n";
    $message .= "\n--$main_boundary--\n";
    mail($to, $subject, $message, $headers);
  }
Peut-etre que je dois ajouter un Message ID dans cette routine ?

Et ce 550_Too_many_invalid_recipients c'est serieux ? Je peux te donner la liste des destinataires si tu le souhaites.

Merci.

Stephane

fritz2cat
31/01/2012, 14h48
1)
koopi.se ne fonctionne pas. Ses serveurs DNS sont cassés.

2)
Les 4 Message-ID différents semblent indiquer que ton applicatif (web-server, ...) a envoyé plusieurs fois le message.

Cependant si l'applicatif a transmis le message sans aucun Message-ID, alors le premier MTA ("processeur de mails") ajoute un Message-ID pour se conformer aux standards.

Un message-ID "normal" devrait posséder un @ et un suffixe qui indique qui a créé ce message-id. Dans ton cas ça manque. L'as-tu gommé ou bien était-il vraiment comme ça ?

Ca fait beaucoup d'anomalies en une fois, tout ça...

Je n'ai même pas parlé du 550_Too_many_invalid_recipients. N'ayant pas la liste des destinataires, impossible de poser un diagnostic.

Frédéric

stephaneeybert
31/01/2012, 12h28
Le probleme est toujours la.

J'ai recu 4 messages identiques dans le foulee dans ma boite mails.

Ils ont des Message-ID differents:

Message-ID: 20120131110808.12932
Message-ID: 20120131110808.12931
Message-ID: 20120131110808.12934
Message-ID: 20120131110807.12915

La log /var/log/qmail/current affiche:

@400000004f27dd5d31aabab4 starting delivery 49396: msg 347247 to remote lisa.frykholm@vinge.se
@400000004f27dd5d31aabe9c status: local 0/10 remote 20/20
@400000004f27dd5d34f3139c delivery 49391: success: 194.98.114.129_accepted_message./Remote_host_said:_250_OK_id=1RsClI-0004SS-Hj/STARTTLS_proto=TLSv1;_cipher=DHE-RSA-AES256-SHA;_subject=/C=FR/ST=PARIS/L=PARIS_CEDEX_15/O=DIRECTION_GENERALE_DE_L'ADMINISTRATION/OU=MINISTERE_DES_AFFAIRES_ETRANGERES_-_MAE/CN=smtp.diplomatie.gouv.fr;_issuer=/C=ZA/ST=Western_Cape/L=Cape_Town/O=Thawte_Consulting_cc/OU=Certification_Services_Division/CN=Thawte_Premium_Server_CA/emailAddress=premium-server@thawte.com;/
@400000004f27dd5d34f3233c status: local 0/10 remote 19/20
@400000004f27dd5d34f32724 end msg 346966
@400000004f27dd5d34f5ea2c starting delivery 49397: msg 347017 to remote lisa.frykholm@vinge.se
@400000004f27dd5d34f5ee14 status: local 0/10 remote 20/20
@400000004f27dd5d35bec03c delivery 49396: deferral: Connected_to_88.131.75.213_but_greeting_failed./Remote_host_said:_550_Too_many_invalid_recipients/
@400000004f27dd5d35bec80c status: local 0/10 remote 19/20
@400000004f27dd5d35becbf4 starting delivery 49398: msg 347226 to remote lisa.frykholm@vinge.se
@400000004f27dd5d35becbf4 status: local 0/10 remote 20/20
@400000004f27dd5e062858ec delivery 49398: deferral: Connected_to_88.131.75.213_but_greeting_failed./Remote_host_said:_550_Too_many_invalid_recipients/
@400000004f27dd5e062860bc status: local 0/10 remote 19/20
@400000004f27dd5e062864a4 starting delivery 49399: msg 347224 to remote lisa.frykholm@vinge.se
@400000004f27dd5e062864a4 status: local 0/10 remote 20/20
@400000004f27dd5e065548d4 delivery 49397: deferral: Connected_to_88.131.75.213_but_greeting_failed./Remote_host_said:_550_Too_many_invalid_recipients/
@400000004f27dd5e065550a4 status: local 0/10 remote 19/20
@400000004f27dd5e065550a4 starting delivery 49400: msg 347244 to remote lisa.jonsson@koopi.se
@400000004f27dd5e0655548c status: local 0/10 remote 20/20
@400000004f27dd5e193cf1f4 delivery 49399: deferral: Connected_to_88.131.75.213_but_greeting_failed./Remote_host_said:_550_Too_many_invalid_recipients/
@400000004f27dd5e193cf5dc status: local 0/10 remote 19/20
@400000004f27dd5e193cf9c4 starting delivery 49401: msg 347245 to remote lisa.jonsson@koopi.se
@400000004f27dd5e193cfdac status: local 0/10 remote 20/20
@400000004f27dd6033af971c delivery 49400: deferral: CNAME_lookup_failed_temporarily._(#4.4.3)/
@400000004f27dd6033af9eec status: local 0/10 remote 19/20
@400000004f27dd6033af9eec delivery 49401: deferral: CNAME_lookup_failed_temporarily._(#4.4.3)/
@400000004f27dd6033afa2d4 status: local 0/10 remote 18/20
@400000004f27dd6033afa2d4 starting delivery 49402: msg 347251 to remote lisa.jonsson@koopi.se
@400000004f27dd6033afa6bc status: local 0/10 remote 19/20
@400000004f27dd6033afaaa4 starting delivery 49403: msg 347492 to remote susanneg@isgy.se
@400000004f27dd6033afaaa4 status: local 0/10 remote 20/20
@400000004f27dd6308f2274c delivery 49402: deferral: CNAME_lookup_failed_temporarily._(#4.4.3)/
@400000004f27dd6308f22f1c status: local 0/10 remote 19/20

stephaneeybert
17/01/2012, 21h51
Pas bète !

Bon, j'ai pas mal de logs en fait..

vps13495 stephane # ll /var/log/mail*
-rw------- 1 root root 0 2012-01-16 03:10 /var/log/mail.err
-rw------- 1 root root 20 2012-01-16 03:10 /var/log/mail.err.1.gz
-rw------- 1 root root 20 2012-01-09 03:10 /var/log/mail.err.2.gz
-rw------- 1 root root 20 2012-01-02 03:10 /var/log/mail.err.3.gz
-rw------- 1 root root 20 2011-12-26 03:10 /var/log/mail.err.4.gz
-rw------- 1 root root 253076 2012-01-17 22:29 /var/log/mail.info
-rw------- 1 root root 137756 2012-01-16 03:10 /var/log/mail.info.1.gz
-rw------- 1 root root 21532 2012-01-09 03:10 /var/log/mail.info.2.gz
-rw------- 1 root root 20 2012-01-02 03:10 /var/log/mail.info.3.gz
-rw------- 1 root root 721 2011-12-26 03:10 /var/log/mail.info.4.gz
-rw------- 1 root root 289461 2012-01-17 22:36 /var/log/mail.log
-rw------- 1 root root 140333 2012-01-16 03:10 /var/log/mail.log.1.gz
-rw------- 1 root root 23789 2012-01-09 03:10 /var/log/mail.log.2.gz
-rw------- 1 root root 2551 2012-01-02 03:10 /var/log/mail.log.3.gz
-rw------- 1 root root 812 2011-12-26 03:10 /var/log/mail.log.4.gz

vps13495 stephane # tail -30 /var/log/mail.log
Jan 17 20:36:43 vps13495 spamd[6534]: spamd: clean message (4.5/6.0) for qscand:509 in 0.5 seconds, 3689 bytes.
Jan 17 20:36:43 vps13495 spamd[6534]: spamd: result: . 4 - HTML_IMAGE_ONLY_32,HTML_MESSAGE,HTML_MIME_NO_HTML_ TAG,MIME_HTML_ONLY,RCVD_IN_NJABL_SPAM,RDNS_NONE scantime=0.5,size=3689,user=qscand,uid=509,require d_score=6.0,rhost=localhost,raddr=127.0.0.1,rport= 34569,mid=<20120117192232.C54A985A8312@groupemailf oryou.com>,autolearn=no
Jan 17 20:36:43 vps13495 spamd[5159]: prefork: child states: II
Jan 17 20:36:43 vps13495 qmail-scanner[8287]: Clear:RC:0(82.97.18.162):SA:0(4.5/6.0): 0.50826 3643 routage@groupemailforyou.com christophe.luciani@europasprak.com La_solution_boissons_chaudes_qui_redonne_le_sourir e <20120117192232.C54A985A8312@groupemailforyou.co m> 1326829002.8289-0.vps13495.ovh.net:2858
Jan 17 20:48:28 vps13495 spamd[6534]: spamd: connection from localhost [127.0.0.1] at port 56085
Jan 17 20:48:28 vps13495 spamd[6534]: spamd: checking message <002c01ccd561$d9cce690$8d66b3b0$@com> for qscand:509
Jan 17 20:48:30 vps13495 spamd[6534]: spamd: clean message (4.2/6.0) for qscand:509 in 1.6 seconds, 5697 bytes.
Jan 17 20:48:30 vps13495 spamd[6534]: spamd: result: . 4 - FSL_HELO_NON_FQDN_1,HELO_NO_DOMAIN,HTML_MESSAGE,RC VD_IN_BL_SPAMCOP_NET,RCVD_IN_BRBL_LASTEXT,RDNS_NON E scantime=1.6,size=5697,user=qscand,uid=509,require d_score=6.0,rhost=localhost,raddr=127.0.0.1,rport= 56085,mid=<002c01ccd561$d9cce690$8d66b3b0$@com>,au tolearn=no
Jan 17 20:48:30 vps13495 spamd[5159]: prefork: child states: II
Jan 17 20:48:30 vps13495 qmail-scanner[9022]: Clear:RC:0(77.126.64.82):SA:0(4.2/6.0): 1.634691 5656 scruplegogo@wixgame.com christophe.luciani@europasprak.com Britney_throws_off_top <002c01ccd561$d9cce690$8d66b3b0$@com> 1326829708.9024-1.vps13495.ovh.net:4319 1326829708.9024-0.vps13495.ovh.net:72
Jan 17 21:36:09 vps13495 vpopmail[12086]: vchkpw-pop3: vpopmail user not found contact@pixam.fr:209.85.210.163
Jan 17 21:51:35 vps13495 spamd[6534]: spamd: connection from localhost [127.0.0.1] at port 51574
Jan 17 21:51:35 vps13495 spamd[6534]: spamd: checking message <1326833532.19590.YahooMailNeo@web29605.mail.ird.y ahoo.com> for qscand:509
Jan 17 21:51:38 vps13495 spamd[6534]: spamd: clean message (3.0/6.0) for qscand:509 in 3.3 seconds, 5027 bytes.
Jan 17 21:51:38 vps13495 spamd[6534]: spamd: result: . 3 - FREEMAIL_FROM,HTML_MESSAGE,MISSING_SUBJECT,RCVD_IN _DNSWL_NONE,RDNS_NONE,RFC_ABUSE_POST scantime=3.3,size=5027,user=qscand,uid=509,require d_score=6.0,rhost=localhost,raddr=127.0.0.1,rport= 51574,mid=<1326833532.19590.YahooMailNeo@web29605. mail.ird.yahoo.com>,autolearn=no
Jan 17 21:51:38 vps13495 spamd[5159]: prefork: child states: II
Jan 17 21:51:38 vps13495 qmail-scanner[12980]: Clear:RC:0(212.82.109.251):SA:0(3.0/6.0): 3.33717 4984 elisabethluciani@yahoo.fr christophe.luciani@europasprak.com <> <1326833532.19590.YahooMailNeo@web29605.mail.ird.y ahoo.com> 1326833495.12982-1.vps13495.ovh.net:1291 1326833495.12982-0.vps13495.ovh.net:797
Jan 17 21:53:08 vps13495 spamd[6534]: spamd: connection from localhost [127.0.0.1] at port 51575
Jan 17 21:53:08 vps13495 spamd[6534]: spamd: checking message <002801ccd562$7aeff800$70cfe800$@net> for qscand:509
Jan 17 21:53:08 vps13495 spamd[6534]: spamd: identified spam (7.8/6.0) for qscand:509 in 0.4 seconds, 5731 bytes.
Jan 17 21:53:08 vps13495 spamd[6534]: spamd: result: Y 7 - FSL_HELO_NON_FQDN_1,HELO_NO_DOMAIN,HTML_MESSAGE,RC VD_IN_BRBL_LASTEXT,RCVD_IN_PBL,RCVD_IN_RP_RNBL,RDN S_NONE scantime=0.4,size=5731,user=qscand,uid=509,require d_score=6.0,rhost=localhost,raddr=127.0.0.1,rport= 51575,mid=<002801ccd562$7aeff800$70cfe800$@net>,au tolearn=no
Jan 17 21:53:09 vps13495 spamd[5159]: prefork: child states: II
Jan 17 21:53:09 vps13495 qmail-scanner[13117]: Clear:RC:0(178.56.248.105):SA:1(7.8/6.0): 0.394237 5685 posterityplato@alobrasil.net christophe.luciani@europasprak.com Booze,_babes_and_more <002801ccd562$7aeff800$70cfe800$@net> 1326833588.13119-0.vps13495.ovh.net:86 1326833588.13119-1.vps13495.ovh.net:4333
Jan 17 22:29:32 vps13495 spamd[6534]: spamd: connection from localhost [127.0.0.1] at port 45008
Jan 17 22:29:32 vps13495 spamd[6534]: spamd: checking message <005601ccd2c0$acccd2c0$06667840$@com> for qscand:509
Jan 17 22:29:32 vps13495 spamd[6534]: spamd: identified spam (8.5/6.0) for qscand:509 in 0.3 seconds, 5701 bytes.
Jan 17 22:29:32 vps13495 spamd[6534]: spamd: result: Y 8 - FSL_HELO_NON_FQDN_1,HELO_NO_DOMAIN,HTML_MESSAGE,RC VD_IN_BRBL_LASTEXT,RCVD_IN_PBL,RCVD_IN_RP_RNBL,RCV D_IN_SORBS_DUL,RCVD_IN_XBL,RDNS_NONE scantime=0.3,size=5701,user=qscand,uid=509,require d_score=6.0,rhost=localhost,raddr=127.0.0.1,rport= 45008,mid=<005601ccd2c0$acccd2c0$06667840$@com>,au tolearn=no
Jan 17 22:29:32 vps13495 spamd[5159]: prefork: child states: II
Jan 17 22:29:32 vps13495 qmail-scanner[15474]: Clear:RC:0(122.168.225.57):SA:1(8.5/6.0): 0.290713 5658 dragoonslater@voanews.com christophe.luciani@europasprak.com Sex_will_never_be_the_same_again_ <005601ccd2c0$acccd2c0$06667840$@com> 1326835772.15476-1.vps13495.ovh.net:4308 1326835772.15476-0.vps13495.ovh.net:61
Jan 17 22:36:09 vps13495 vpopmail[15873]: vchkpw-pop3: vpopmail user not found contact@pixam.fr:209.85.210.143
vps13495 stephane #

Le tail me montre qu'il y a du spam.. mais je ne sais pas trop comment voir les mails qe j'ai envoyé.. C'était déjà il y a 2 jours..

Je me rend compte que l'envoi n'écrit ni dans

tail -f /var/log/mail.info

ni dans

tail -f /var/log/mail.log

Du coup, je ne sais pas trop où voir ça..

fritz2cat
17/01/2012, 16h01
Comme tu as un dédié (VPS = dédié dans ce cas-ci) les logs sont chez toi, normalement dans /var/log

De là tu peux voir s'il y a réellement eu 5 envois pour chaque destinataire.

Si tu possèdes les 5 exemplaires d'un seul de ces messages, analyse les en-têtes SMTP et compare les 5 "Message-id" entre eux et avec ceux dans tes logs.

Frédéric

stephaneeybert
16/01/2012, 21h51
Jai la distribution Release 2 OVH (Gentoo) - 64 bits (English) sur un VPS.

Je fais un appel à la fonction mail() pour chaque adresse email.

Ca marche bien chez un autre hébergeur (Sivit.fr) depuis des années.

Mais le site web en question vient d'être déménagé sur mon nouveau serveur chez OVH.

Okinou
16/01/2012, 21h30
Avec quel logiciel ? Sur quel hébergement ?

stephaneeybert
16/01/2012, 21h22
Bonjour,

Un mailing a été envoyé, ou tout du mois reçu, 5 fois par tous les récipients, 3000 personnes.. ça fait du monde quand même.

J'ai fais des essais suite à cela mais le problème ne se reproduit pas.

Je me demande si cela est déjà arrivé à d'autres.

Stephane