Jump to content

Newsletter


Recommended Posts

Is there anything I should change on this code? I'll use it to send about 20000 emails... I don't like this one, because while sending the emails, the page keep loading... I kind dont "trust" on this script..

 

index.php

<?php

include('config.php');
include('class.phpmailer.php');
include('email.php');

// Get users info
$getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'";
$getUser_not_sent = mysql_query($getUser_sql_not_sent);
$getUser_num_not_sent = mysql_num_rows($getUser_not_sent);

$getUser_sql_sent = "SELECT * FROM emails WHERE sent = '1'";
$getUser_sent = mysql_query($getUser_sql_sent);
$getUser_num_sent = mysql_num_rows($getUser_sent);

$getUser_sql_all = "SELECT * FROM emails";
$getUser_all = mysql_query($getUser_sql_all);
$getUser_num_all = mysql_num_rows($getUser_all);

$getUser_sql_accessed = "SELECT * FROM emails WHERE accessed = '1'";
$getUser_accessed = mysql_query($getUser_sql_accessed);
$getUser_num_accessed = mysql_num_rows($getUser_accessed);

$money = $getUser_num_accessed * 0.20;
$money_formated = number_format($money, 2, ',', '');

$x = $getUser_num_sent * 100;
$y = $getUser_num_all;
$percentage = $x / $y;
$percentage_formated = number_format($percentage, 0, '', '');

if ($getUser_num_not_sent == $getUser_num_all) {
echo '<form action = "send.php" method = "post">';
echo '<strong>Assunto do Email</strong><br />';
echo $emailSubject;
echo '<br />';
echo '<strong>Corpo do Email</strong><br />';
echo $emailBody;
echo '<br /><br />';
echo '<input name = "send" type = "submit" value = "Enviar Emails" />';
echo '</form>';
} else {
echo "Foram enviados " . $percentage_formated . "&#37; dos emails. " . $getUser_num_accessed . " acessaram o site, bonificação de R&#36; " . $money_formated . " para o Claudius Ibn.";
}

?>

 

<?php 

include('config.php');
include('class.phpmailer.php');
include('email.php');

echo 'Os emails estao sendo enviados, voce pode sair do site que o processo continuara mesmo assim.';

// Get users info
$getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'";
$getUser_not_sent = mysql_query($getUser_sql_not_sent);
$getUser_num_not_sent = mysql_num_rows($getUser_not_sent);

$mail = new PHPMailer();

while ($row = mysql_fetch_array($getUser_not_sent)) {
// Get the current user's email
$emailUser = $row['email'];
// Define mail object and mail parameters
$mail -> From = 'campainha@ibnshare.com';
$mail -> FromName = 'Campainha';
$mail -> AddAddress($emailUser);
$mail -> Subject = $emailSubject;
$mail -> Body = $emailBody;
// Send and verify
if(!$mail -> Send()) {
	echo 'Erro: '. $mail -> ErrorInfo;
} else {
	mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'");
}
sleep(30);
}

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.