Settato body del messaggio in utf8. Implementata scrittura nel db delle email inviate. Commentato l'invio tramite smtp.

This commit is contained in:
root 2016-10-16 20:20:06 +02:00
parent e776d41d95
commit 6bd0f58e9d

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);