PHP
<?php
#####################################
# Function to Read a file
# and store all data into a variable
#####################################
function readTemplateFile($FileName) {
$fp = fopen($FileName,"r") or exit("Unable to open File ".$FileName);
$str = "";
while(!feof($fp)) {
$str .= fread($fp,1024);
}
return $str;
}
require 'PHPMailerAutoload.php';
if (isset($_POST['verzenden'])){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '[email protected]'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'root'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = '[email protected]';
$mail->addReplyTo('[email protected]');
$email = sendTo();
foreach ($email as $em) {
$mail->addAddress($em["email"],"" . $em["voornaam"] . " " . $em["naam"]);
}
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST["onderwerp"];
$mail->Body = readTemplateFile("nieuwsbrief/index.php");
$mail->AltBody = 'Gebruik a.u.b een e-mail client die html aankan.';
if(!$mail->send()) {
echo 'Er is iets fout gelopen! Neem een kop koffie en contacteer Mitchell Verbruggen';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'De nieuwsbrief is verzonden!';
}
}
function sendTo(){
include 'connect.php';
$emails = $dbh->query("SELECT voornaam, naam, email FROM abonee WHERE actief = '0'");
$email = array();
$i = 0;
foreach($emails as $var) {
$email[$i] = $var;
$i++;
}
return $email;
}
?>
Toon Meer
weet dat deze code werkt heb met phpmailer ook een heel gedoe gehad