mlMemberRoller/sender.php
2016-10-16 17:06:33 +02:00

54 lines
1.7 KiB
PHP

<?php
require_once 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
include_once 'config/config.php';
function getToken($length = 12){
return uniqId();
//PHP7
//return bin2hex(random_bytes($length));
}
function generateLink($url, $token, $ml, $email){
$link = $url."/mlrollmember/stayin.php?";
$token = "token=".$token;
$ml = "&ml=".$ml;
$email = "&email=".$email;
return $link.$token.$ml.$email;
}
$mail = new PHPMailer;
//$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->setFrom($sender, $senderName);
$mail->Subject = $subject;
$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;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
}
fclose($file);