Ich hab mir da ein Newsletterscript zusammen gebastelt.
es funktioniert, aber ich habe gelesen, dass phpmailer ein Problem mit vielen Adressen hat. Hat jemand Erfahrungen damit? Kann ich mit diesem Script sagen wir mal 1000 Mails raus lassen?
PHP:
<?php
# Include DB File
include_once 'db.php';
# Include PHP Mailer Class
include_once("class.phpmailer.php");
?>
<?php
# Function to send email
function sendEmail ($toEmail, $subject, $emailBody, $altBody) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "HOST";
$mail->SMTPAuth = true;
$mail->Username = 'USERMAIL';
$mail->Password = 'USERPASSWORD';
$mail->From="FROMMAIL";
$mail->FromName="FROM NAME";
$mail->AddAddress("$toEmail"); // Add a recipient
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $emailBody;
$mail->AltBody= $altBody;
if(!$mail->Send()) {
return false;
} else {
return true;
}
#clears the recipient address
$mail->ClearAddresses();
}
# 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;
}
?>
<?php
# Finally send email
//Read Template File
$emailBody = readTemplateFile("template.html");
$altBody = "TEXT";
$sql = 'SELECT email, firstname, name '
. 'FROM user ';
. 'WHERE newsletter = 1 ';
foreach ($db->query($sql) as $row) {
//Data to be sent (Ideally fetched from Database)
$betreff = "BLABLA Newsletter";
$mailadresse = $row['email'];
$vorname = $row['firstname'];
$nachname = $row['name'];
$UserEmail = "'$mailadresse', '$vorname $nachname'";
//Send email
$emailStatus = sendEmail ($UserEmail, $betreff, $emailBody, $altBody);
//If email function return false
if ($emailStatus != 1) {
echo "An error occured while sending email. Please try again later.";
} else {
echo "Email with account details were sent successfully.";
}
}
?>
es funktioniert, aber ich habe gelesen, dass phpmailer ein Problem mit vielen Adressen hat. Hat jemand Erfahrungen damit? Kann ich mit diesem Script sagen wir mal 1000 Mails raus lassen?