Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New features (see description)

Now, if there are not valid email addresses, the mailer will stop trying
to send after a predefined limit, that has been set in config.php
(max_allowed_fails).

It's now possible to add new users to a preexisting mailing list by just
updating it.
  • Loading branch information...
commit e81f056ae6f4f7b2ad7d3ece2a191bde3df14b1f 1 parent 3a1fbf8
@simonewebdesign authored
View
2  Lista.php
@@ -1 +1 @@
-<?php
+<?php
View
21 User.php
@@ -64,8 +64,7 @@ static function setMailAsReceived($id) {
}
static function resetFetch() {
- $s = self::$db->prepare("UPDATE users SET has_received_mail=0");
- return $s->execute();
+ return self::$db->exec("UPDATE users SET has_received_mail=0, fails=0");
}
static function all($limit=0) {
@@ -122,6 +121,24 @@ static function toBeSent($limit, $list_id) {
return $s->fetchAll(PDO::FETCH_OBJ);
}
}
+
+ static function increment_fails($id) {
+ if ($id > 0) {
+ $q = "UPDATE `users` SET `fails`=`fails`+1 WHERE `id`=?";
+ $s = self::$db->prepare($q);
+ return $s->execute(array($id));
+ }
+ return false;
+ }
+
+ static function get_invalid_ones_by_list_id($list_id, $max_allowed_fails=5){
+ if ($list_id > 0) {
+ $q = "SELECT * from `users` WHERE `list_id`=? AND `fails`>=?";
+ $s = self::$db->prepare($q);
+ return $s->execute(array($list_id, $max_allowed_fails));
+ }
+ return false;
+ }
}
View
2  _list_form.php
@@ -1 +1 @@
-<form method=POST>
+<form method=POST>
View
2  _user_form.php
@@ -1 +1 @@
-<form method=POST>
+<form method=POST>
View
5 config.php
@@ -41,10 +41,11 @@
# miscellaneous
'language' => 'it',
'regex' => '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$^',
- 'limit' => 100, # limit of emails to send before refreshing the send.php page
+ 'limit' => 300, # limit of emails to send before refreshing the send.php page
'word_wrap' => 50,
'timeout' => 10000, # refresh timeout, in milliseconds.
'debug_mode' => 0, # enables SMTP debug information (2 for testing)
'smtp_auth' => true,
- 'charset' => 'UTF-8'
+ 'charset' => 'UTF-8',
+ 'max_allowed_fails' => 5
);
View
36 list_create.php
@@ -13,39 +13,11 @@
if ( isset($_POST['submit']) ) {
if ( Lista::create($_POST['name']) ) {
-
- $list_id = $db->lastInsertId();
-
- // fetch email addresses and remove duplicates
- $separator = "\r\n";
-
- $duplicated_array = explode($separator, $_POST['email_addresses']); var_dump($duplicated_array);
- $sanitized_array = array_unique($duplicated_array); var_dump($sanitized_array);
-
- foreach ($sanitized_array as $email_address) {
- if ( !empty($email_address) ) {
- if ( User::create($email_address) ) {
- echo "<p><b>$email_address</b> aggiunto con successo alla lista <b>{$_POST['name']}</b>.";
- } else {
- echo "<p>ERRORE durante l'inserimento di <b>$email_address</b>.";
- }
- }
- }
-
- $input_rows = count($duplicated_array);
- $output_rows = count($sanitized_array);
- $dupes = $input_rows - $output_rows;
-
- echo "Operazione conclusa con successo!<br>";
- echo "Email iniziali: $input_rows<br>";
- echo "Email finali: $output_rows<br>";
- echo "Duplicati rimossi: $dupes<br>";
-
- $update_list_id = $db->prepare("UPDATE users SET list_id = $list_id WHERE list_id <= 0");
- $update_list_id->execute();
-
-
+
echo SUCCESS;
+ $list_id = $db->lastInsertId();
+ include 'save_users_in_list.php';
+
} else {
echo FAIL;
}
View
12 list_update.php
@@ -2,6 +2,7 @@
include_once 'bootstrap.php';
include_once 'Lista.php';
+include_once 'User.php';
################################
@@ -10,10 +11,15 @@
$l = Lista::read($_GET['id']);
if (isset($_POST['submit'])) {
- if ( Lista::update($_POST['name']) ) {
- echo SUCCESS;
+ if ( Lista::update($_GET['id'], $_POST['name']) ) {
+ echo SUCCESS; // relativo solo alla lista, non agli utenti
+
+ $list_id = $_GET['id'];
+
+ include 'save_users_in_list.php';
+
} else {
- echo FAIL;
+ echo FAIL . " La lista non e' stata aggiornata.";
}
}
View
24 save_users_in_list.php
@@ -0,0 +1,24 @@
+<?php
+
+// fetch email addresses and remove duplicates
+$emails = Lista::remove_duplicates_from($_POST['email_addresses']);
+
+/* Saves users in the list.
+* @param $list_id the ID of the mailing list you want to save the users to.
+* @param $emails an array of unique emails.
+*
+*/
+foreach ($emails as $email) {
+ if ( !empty($email) && User::findByEmail($email) == false ) { // user doesn't exist yet
+ if ( User::create($email) ) {
+ echo "<p><b>$email</b> aggiunto con successo alla lista <b>{$_POST['name']}</b>.";
+ }
+ else {
+ // Probabilmente fallisce perche` e` gia` nel db.
+ echo "<p>ERRORE durante l'inserimento di <b>$email</b>.";
+ }
+ }
+}
+// Setto la list_id all'id della lista corrente, cosi' l'aggiunta e' completa
+$update_list_id = $db->prepare("UPDATE users SET list_id = $list_id WHERE list_id <= 0");
+$update_list_id->execute();
View
2  send.php
@@ -1 +1 @@
-<?php
+<?php
View
2  user_create.php
@@ -16,7 +16,7 @@
if ( User::create($_POST['email'], $_POST['name'], $_POST['list_id']) ) {
echo SUCCESS;
} else {
- echo FAIL;
+ echo FAIL . " L'Utente non e' stato creato (Probabilmente esiste gia').";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.