Compare commits
2 commits
6bd0f58e9d
...
eef27cac21
Author | SHA1 | Date | |
---|---|---|---|
|
eef27cac21 | ||
|
e7185c203c |
2 changed files with 103 additions and 29 deletions
60
loader.php
Normal file
60
loader.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
include_once 'config/config.php';
|
||||
include_once "vendor/notorm/NotORM.php";
|
||||
|
||||
//exit('Commentami, lanciami e ricommentami.');
|
||||
|
||||
function getToken($length = 12){
|
||||
return uniqId();
|
||||
//PHP7
|
||||
//return bin2hex(random_bytes($length));
|
||||
}
|
||||
|
||||
$pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
|
||||
$db_user,
|
||||
$db_pass
|
||||
);
|
||||
|
||||
function getMyDateFormatted($datestr){
|
||||
$date = null;
|
||||
if(empty($datestr)){
|
||||
$date = new DateTime();
|
||||
} else {
|
||||
$date = new DateTime($datestr);
|
||||
}
|
||||
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
|
||||
|
||||
$db = new NotORM($pdo);
|
||||
|
||||
$db->debug = true;
|
||||
|
||||
$today = getMyDateFormatted("");
|
||||
$last = getMyDateFormatted($rollday);
|
||||
|
||||
//Inserisco la mailing list e ottengo l'id
|
||||
$ret = $db->roll()->insert(array(
|
||||
"ml" => $ml,
|
||||
"startroll" => $today,
|
||||
"endroll" => $last
|
||||
));
|
||||
|
||||
$file = fopen($filename, "r");
|
||||
while(!feof($file)){
|
||||
$line = fgets($file);
|
||||
$sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL);
|
||||
if($sanitized_mail !== "") {
|
||||
$token = getToken();
|
||||
|
||||
//Inserisco le mail dei membri della mailing list
|
||||
$db->$db_table()->insert(array(
|
||||
"id" => $ret['id'],
|
||||
"token" => $token,
|
||||
"email" => $sanitized_mail
|
||||
));
|
||||
}
|
||||
}
|
||||
fclose($file);
|
72
sender.php
72
sender.php
|
@ -3,13 +3,7 @@ require_once 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
|
|||
include_once 'config/config.php';
|
||||
include_once "vendor/notorm/NotORM.php";
|
||||
|
||||
exit('Commentami, lanciami e ricommentami.');
|
||||
|
||||
function getToken($length = 12){
|
||||
return uniqId();
|
||||
//PHP7
|
||||
//return bin2hex(random_bytes($length));
|
||||
}
|
||||
//exit('Commentami, lanciami e ricommentami.');
|
||||
|
||||
function generateLink($url, $token, $ml, $email){
|
||||
$link = $url."/mlMemberRoller/stayin.php?";
|
||||
|
@ -44,31 +38,51 @@ $mail->isHTML(false); // Set email format to HTML
|
|||
$mail->setFrom($sender, $senderName);
|
||||
$mail->Subject = $subject;
|
||||
|
||||
//$db->debug = true;
|
||||
$db->debug = true;
|
||||
|
||||
$file = fopen($filename, "r");
|
||||
while(!feof($file)){
|
||||
$line = fgets($file);
|
||||
$sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL);
|
||||
if($sanitized_mail !== "") {
|
||||
$mail->addAddress($sanitized_mail);
|
||||
$token = getToken();
|
||||
$link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail);
|
||||
$mail->Body = $def_body.$link;
|
||||
//cerco la ml che ha lo end date.
|
||||
//prendo l'id
|
||||
//prendo tutte le email con quel id che hanno renewed = 0
|
||||
//ciclo
|
||||
function getMyDateFormatted($datestr){
|
||||
$date = null;
|
||||
if(empty($datestr)){
|
||||
$date = new DateTime();
|
||||
} else {
|
||||
$date = new DateTime($datestr);
|
||||
}
|
||||
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
$db->$db_table()->insert(array(
|
||||
"token" => $token,
|
||||
"ml" => $ml,
|
||||
"email" => $sanitized_mail
|
||||
));
|
||||
$last = getMyDateFormatted($rollday);
|
||||
$rolls = $db->roll()->where(array(
|
||||
"ml" => $ml,
|
||||
"endroll" => $last
|
||||
));
|
||||
|
||||
if(!$mail->send()) {
|
||||
echo 'Message could not be sent.'."\n";
|
||||
echo 'Mailer Error: ' . $mail->ErrorInfo."\n";
|
||||
} else {
|
||||
echo 'Message has been sent'."\n";
|
||||
|
||||
foreach($rolls as $roll) {
|
||||
$members = $db->$db_table()->where(array(
|
||||
"id" => $roll['id'],
|
||||
"renewed" => 0
|
||||
));
|
||||
|
||||
foreach($members as $member) {
|
||||
$sanitized_mail = filter_var($member['email'], FILTER_SANITIZE_EMAIL);
|
||||
if($sanitized_mail !== "") {
|
||||
|
||||
$mail->addAddress($sanitized_mail);
|
||||
$token = $member['token'];
|
||||
$link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail);
|
||||
$mail->Body = $def_body.$link;
|
||||
|
||||
if(!$mail->send()) {
|
||||
echo 'Message could not be sent.'."\n";
|
||||
echo 'Mailer Error: ' . $mail->ErrorInfo."\n";
|
||||
} else {
|
||||
echo 'Message has been sent'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
fclose($file);
|
||||
|
|
Loading…
Reference in a new issue