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