Compare commits

...

2 commits

2 changed files with 69 additions and 27 deletions

View file

@ -3,6 +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();
@ -11,7 +12,7 @@ function getToken($length = 12){
}
function generateLink($url, $token, $ml, $email){
$link = $url."/mlrollmember/stayin.php?";
$link = $url."/mlMemberRoller/stayin.php?";
$token = "token=".$token;
$ml = "&ml=".$ml;
$email = "&email=".$email;
@ -25,42 +26,49 @@ $pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
);
$db = new NotORM($pdo);
var_dump($db);
exit();
$mail = new PHPMailer;
$mail->setLanguage($lang, 'vendor/phpmailer/phpmailer/language/phpmailer.lang-'.$lang.'.php');
$mail->CharSet = 'utf-8';
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtpHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $sender; // SMTP username
$mail->Password = $credential_pw; // SMTP password
$mail->SMTPSecure = $algo_sec; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $post; // TCP port to connect to
$mail->isHTML(false); // Set email format to HTML
//$mail->SMTPDebug = 5; // Enable verbose debug output
//$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtpHost; // Specify main and backup SMTP servers
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = $sender; // SMTP username
//$mail->Password = $credential_pw; // SMTP password
//$mail->SMTPSecure = $algo_sec; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port; // TCP port to connect to
$mail->isHTML(false); // Set email format to HTML
$mail->setFrom($sender, $senderName);
$mail->Subject = $subject;
//$db->debug = true;
$file = fopen($filename, "r");
while(!feof($file)){
$line = fgets($file);
$sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL);
if($sanitized_mail !== false) {
$mail->addAddress($sanitized_mail);
$token = getToken();
$link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail);
$mail->AltBody = $def_body.$link;
$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;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
$db->$db_table()->insert(array(
"token" => $token,
"ml" => $ml,
"email" => $sanitized_mail
));
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);

View file

@ -1,3 +1,37 @@
<?php
include_once 'config/config.php';
include_once "vendor/notorm/NotORM.php";
$pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
$db_user,
$db_pass
);
$db = new NotORM($pdo);
if( isset($_GET['token']) && !empty($_GET['token']) &&
isset($_GET['ml']) && !empty($_GET['ml']) &&
isset($_GET['email']) && !empty($_GET['email']) ) {
$token = $_GET['token'];
$ml = $_GET['ml'];
$email = $_GET['email'];
$affected = $db->$db_table()->where(array(
"token" => $token,
"ml" => $ml,
"email" => $email
))->update(array(
"renewed" => 1,
));
if($affected == 1) {
echo "Hai rinnovato l'inscrizione.";
} else {
echo "Si è verificato un errore.";
}
}
?>