Prende le mail da spedire dal database

This commit is contained in:
root 2016-10-20 01:37:54 +02:00
parent 6bd0f58e9d
commit e7185c203c

View file

@ -3,13 +3,7 @@ require_once 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
include_once 'config/config.php'; include_once 'config/config.php';
include_once "vendor/notorm/NotORM.php"; include_once "vendor/notorm/NotORM.php";
exit('Commentami, lanciami e ricommentami.'); //exit('Commentami, lanciami e ricommentami.');
function getToken($length = 12){
return uniqId();
//PHP7
//return bin2hex(random_bytes($length));
}
function generateLink($url, $token, $ml, $email){ function generateLink($url, $token, $ml, $email){
$link = $url."/mlMemberRoller/stayin.php?"; $link = $url."/mlMemberRoller/stayin.php?";
@ -44,31 +38,51 @@ $mail->isHTML(false); // Set email format to HTML
$mail->setFrom($sender, $senderName); $mail->setFrom($sender, $senderName);
$mail->Subject = $subject; $mail->Subject = $subject;
//$db->debug = true; $db->debug = true;
$file = fopen($filename, "r"); //cerco la ml che ha lo end date.
while(!feof($file)){ //prendo l'id
$line = fgets($file); //prendo tutte le email con quel id che hanno renewed = 0
$sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL); //ciclo
if($sanitized_mail !== "") { function getMyDateFormatted($datestr){
$mail->addAddress($sanitized_mail); $date = null;
$token = getToken(); if(empty($datestr)){
$link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail); $date = new DateTime();
$mail->Body = $def_body.$link; } else {
$date = new DateTime($datestr);
}
return $date->format('Y-m-d');
}
$db->$db_table()->insert(array( $last = getMyDateFormatted($rollday);
"token" => $token, $rolls = $db->roll()->where(array(
"ml" => $ml, "ml" => $ml,
"email" => $sanitized_mail "endroll" => $last
)); ));
if(!$mail->send()) {
echo 'Message could not be sent.'."\n"; foreach($rolls as $roll) {
echo 'Mailer Error: ' . $mail->ErrorInfo."\n"; $members = $db->$db_table()->where(array(
} else { "id" => $roll['id'],
echo 'Message has been sent'."\n"; "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);