devofash Posted February 26, 2010 Share Posted February 26, 2010 Hi Guys, Need some help. I'm using phpmailer (for php4) i'm reading a textfile with about 200 email addresses and i'm sending 20 emails every 5 seconds. Works perfectly. But got a major problem, a lot of clients have comeback to me and said that they've received the same copy multiple times. I can't figure out why its doing this can someone please help me resolve this ?? Many thanks. <?php error_reporting(0); set_time_limit(0); include_once('phpmailer/class.phpmailer.php'); $body = 'This is a test'; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = ""; $mail->From = "Me"; $mail->FromName = "FromName"; $mail->Subject = "Subject"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML($body); $myFile = "listmanagement/uploads/34_250210_1267104673.txt"; $data = file("$myFile"); foreach($data as $value) { $v = trim($value); $emails .= "$v,"; } $email_addrs = explode(",", $emails); $throttle = 20; $i = 0; // Now, run a loop through all the email addresses in the mailing list. foreach($email_addrs as $email_addr) { if ($i % $throttle == 0) { sleep(5); } $mail->AddBCC($email_addr); $mail->Send(); $mail->ClearBCCs(); $i++; } $mail->AddAddress("me@me.com", "Company"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 26, 2010 Share Posted February 26, 2010 Are you only receiving one copy at the "me@me.com" address? Have you examined the list stored in the file to make sure it does not contain duplicates for those members that have indicated they are receiving duplicates? Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018471 Share on other sites More sharing options...
devofash Posted February 26, 2010 Author Share Posted February 26, 2010 Hi Thanks you for the reply. The list is clean, no duplicates Yes I'm receiving a few copies too. Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018498 Share on other sites More sharing options...
PFMaBiSmAd Posted February 26, 2010 Share Posted February 26, 2010 Yes I'm receiving a few copies too. Then it is likely your browser is requesting the page twice. Different browsers do this for different reasons and you can also have some url rewriting that is causing it. FF is the biggest offender because some of the add-on debugging tools cause a page to be requested twice and it used to (I think this bug has been fixed) request a page twice when the default character encoding set in the browser does not match the page encoding. The best general purpose solution is to use a session variable to allow the page to only be processed once per 'browser session', something like this - <?php session_start(); if(isset($_SESSION['oneshot'])){ die('The page has already been requested this browser session.'); } $_SESSION['oneshot'] = TRUE; // the remainder of your code on the page here... ?> Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018503 Share on other sites More sharing options...
devofash Posted February 26, 2010 Author Share Posted February 26, 2010 Hi thanks for that. Here's the thing, whilst in testing i'm using about 4/5 emails addresses (don't want to spam the clients) and the script works perfectly with my code. But as soon as I try it with live data its screwes up. Is there anything wrong with my foreach loop? Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018540 Share on other sites More sharing options...
PFMaBiSmAd Posted February 26, 2010 Share Posted February 26, 2010 Also, the code you posted is not checking in any way how or who requested the page, so, anytime the page is requested, by a search engine or some other bot script, it will send emails. You would need to add login/authentication logic to insure that the code on the page only executes when YOU submit or browse to the page. Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018541 Share on other sites More sharing options...
devofash Posted February 26, 2010 Author Share Posted February 26, 2010 Its got all that, I just removed all that stuff just to keep the focus on the main script. I still don't understand why it sends out duplicate emails when I use it with 200 emails. I don't want to spam my clients again. Is there a feature in PHPMailer where I test it with my list ... without actually sending it out to my clients? Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018558 Share on other sites More sharing options...
PFMaBiSmAd Posted February 26, 2010 Share Posted February 26, 2010 Its got all that ... Are you sure it is working, because a lot of people's security code does not actually prevent the 'protected' code on the page from being executed while the browser is requesting the new URL due to a redirect. Is there a feature in PHPMailer where ... Nope. You would need to log the actual information being generated for the emails (edit: and comment out the line that is actually sending the email) - http://us.php.net/manual/en/function.error-log.php If you include a date/time and the IP address where the page request came from as part of the information you log, you should be able to determine if this is due to your browser making multiple page requests. If these people have supplied their email address and they are receiving duplicates, that would not be considered spamming, unless the email is spam. Quote Link to comment https://forums.phpfreaks.com/topic/193440-phpmailer-sending-duplicates/#findComment-1018567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.