mlMemberRoller/sender.php

75 lines
2 KiB
PHP
Raw Normal View History

2016-10-16 17:06:33 +02:00
<?php
require_once 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
include_once 'config/config.php';
2016-10-16 17:44:52 +02:00
include_once "vendor/notorm/NotORM.php";
exit('Commentami, lanciami e ricommentami.');
2016-10-16 17:06:33 +02:00
function getToken($length = 12){
return uniqId();
//PHP7
//return bin2hex(random_bytes($length));
}
function generateLink($url, $token, $ml, $email){
$link = $url."/mlMemberRoller/stayin.php?";
2016-10-16 17:06:33 +02:00
$token = "token=".$token;
$ml = "&ml=".$ml;
$email = "&email=".$email;
return $link.$token.$ml.$email;
}
2016-10-16 17:44:52 +02:00
$pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
$db_user,
$db_pass
);
$db = new NotORM($pdo);
2016-10-16 17:06:33 +02:00
$mail = new PHPMailer;
$mail->setLanguage($lang, 'vendor/phpmailer/phpmailer/language/phpmailer.lang-'.$lang.'.php');
$mail->CharSet = 'utf-8';
2016-10-16 17:06:33 +02:00
//$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
2016-10-16 17:06:33 +02:00
$mail->setFrom($sender, $senderName);
$mail->Subject = $subject;
//$db->debug = true;
2016-10-16 17:06:33 +02:00
$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;
2016-10-16 17:06:33 +02:00
$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";
2016-10-16 17:06:33 +02:00
}
}
2016-10-16 17:06:33 +02:00
}
fclose($file);