Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-14-2008, 04:13 PM Mass E-mail Help
Skilled Talker

Posts: 69
Trades: 0
Hello all,

Right now I'm trying to make a script that extracts e-mail addresses from my MySQL database and sends an e-mail to every one of them (there's around 500) with the information in my $body tag. I tried it with a test list from the database, and it worked fine, however that was just 15 e-mail addresses. When I put it into work and tried the full database, nobody received the e-mail. I was wondering if anyone could help me out with it or help me find another way to try this.

Here is the code I'm using:

PHP Code:
                $query "SELECT * FROM `newsletter2` ORDER BY `emails` ASC";
                
$result = @mysql_query($query)
                or die(
"Couldn't execute query: " mysql_error());

                while (
$array mysql_fetch_assoc($result)) {
                    
$to $array['emails'];

                
$headers  'MIME-Version: 1.0' "\r\n";
                
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
                
$headers .= 'From: newsletter@indianriverquilts.com' "\r\n";

                
$subject "The Quilt House Newsletter";
                
$body "The following e-mail is from The Quilt House:<br/><br/>We have uploaded a new newsletter to the website.<br/><br/>You can view our current newsletter, or the rest of our website, by clicking <a href='http://www.indianriverquilts.com/newsletter.php' target='_blank'>here.</a><br/><br/>" $description "<br/><br/>Thanks, and we hope to see you in the shop!<br/><br/>-The Quilt House";
                
mail($to$subject$body$headers);    
                
                } 
Thanks in advance!

-Jon Roost
Reality15 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-15-2008, 10:22 PM Re: Mass E-mail Help
Experienced Talker

Posts: 43
Name: Juan Pablo Villaverde
Trades: 0
the mail functions returns a status value, check the return value to be sure about the result, you will be able to guess the problem in this way.
__________________
Omnisciens -
Please login or register to view this content. Registration is FREE
software development

Please login or register to view this content. Registration is FREE
jpablo is offline
Reply With Quote
View Public Profile Visit jpablo's homepage!
 
Old 07-15-2008, 10:57 PM Re: Mass E-mail Help
Skilled Talker

Posts: 69
Trades: 0
Alright, I changed the code to this...

PHP Code:
                $query "SELECT * FROM `newsletter2` ORDER BY `emails` ASC";
                
$result = @mysql_query($query)
                or die(
"Couldn't execute query: " mysql_error());

                while (
$array mysql_fetch_assoc($result)) {
                    
$to $array['emails'];

                
$headers  'MIME-Version: 1.0' "\r\n";
                
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
                
$headers .= 'From: newsletter@indianriverquilts.com' "\r\n";

                
$subject "The Quilt House Newsletter";
                
$body "The following e-mail is from The Quilt House:<br/><br/>We have uploaded a new newsletter to the website.<br/><br/>You can view our current newsletter, or the rest of our website, by clicking <a href='http://www.indianriverquilts.com/newsletter.php' target='_blank'>here.</a><br/><br/>" $description "<br/><br/>Thanks, and we hope to see you in the shop!<br/><br/>-The Quilt House";

                if (
mail($to$subject$body$headers) ) {
                    echo 
$to "<br/>";
                } else {
                    echo 
"<strong>" $to "</strong><br/>";
                } 
                
                } 
Which would mean if the e-mail didn't send, it would make the e-mail it errored at bold. None of the e-mails are bold however, meaning it should have send out...

Any other ideas? I'm lost here.
Reality15 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2008, 10:15 AM Re: Mass E-mail Help
Experienced Talker

Posts: 33
Name: Joseph
Trades: 0
First of all you need a code that will accept only valid e-mail addresses, 'couse this one will send an e-mail to whatever. If you have test added as e-mail, it will mail test.

This will send an e-mail to everyone. Maybe the problem is the number of the e-mails you are trying to send.
Try adding a sleep(5); after echo $to . "<br/>";.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
xmsmmgrs is offline
Reply With Quote
View Public Profile Visit xmsmmgrs's homepage!
 
Old 07-16-2008, 10:32 PM Re: Mass E-mail Help
Skilled Talker

Posts: 69
Trades: 0
Added a sleep into it. And there is already a valid e-mail checker earlier in the code. Still nothing sent out to my subscribers. Any other ideas before I give up?
Reality15 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2008, 10:11 PM Re: Mass E-mail Help
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Here is one I used a while back. I knew all the emails so I didnt validate and I havent checked it with a high number of emails but this might help:

Code:
<?php
include "variables.php";
/*$query   = "SELECT COUNT(userID) AS numrows FROM userdb WHERE emailupdate='1'";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];*/
$count=0;
$result = mysql_query("SELECT * FROM userdb WHERE emailupdate='1'") or die(mysql_error());
while($row = mysql_fetch_array($result))
  {
  if ($row['mlist']!=""){
  $to[$count]=$row['email'];
  $count+=1;
  }
  }
  
$message="RANDOM MESSAGE";
echo "Messages sent to " . $count . " people.<br />";
for ($i=0; $i<=$count; $i++)
	{
		mail($to[$i],"SUBJECT",$message,"From: WHOEVER <who@ever.com>");
		echo $to[$i]. "<br />";
	}
?>
Not the most efficient code in the world probably but it works
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
Old 07-19-2008, 09:01 AM Re: Mass E-mail Help
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I havnt checked the code but just expanding slightly on what xmsmmgrs said, many hosts set limits on how many emails each account can send per hour.

This can be from something like 50 emails/hour to 1000's it depends entirely on how stupid the webhost is...

So first check with your host how many emails you can send an hour.
then you could get clever and have it send them in batchs with hour gaps in between. etc.

Also many hosts require you to send mass mailings in non-peak times IE 3am etc when the server is least used and it wont hog needed resources.

Hope this helps,
Dan

(Rep points apprieciated)
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Mass E-mail Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27349 seconds with 12 queries