Jump to content

php count


kev wood

Recommended Posts

sorry about that, i have created an email distribution system and i need to add a count so when the limit is reached it will not send out anymore emails.  i already have created a count which counts the amount of email address that are imported into the mailing list so i just need to modify this so that it stops importing the address when this limit is reached.  the code i have already is this

 

// construct mailing list array
$merc_list = explode(",",$merc_mailingList);

// deploy the emails
for($i=0; $i<count($merc_list); $i++){

Link to comment
Share on other sites

the code does not need to stop the importing of the email address but just stop the emails being sent out.  i could then write some code to destroy the already constructed mailing list and then start the process over again after an hour has passed.

Link to comment
Share on other sites

i work for a company called acmeart and i have been asked to create an email distribution system.  the user has three different layout options they can choose from.  it works by the user is able to upload images and fill out text boxes.  once they have completed this it then constructs a newsletter by placing these images and text in set places on the page.  then it emails this out to the subscribed mailing lists.  the newsletters are only ever sent out to people who subscribe to them and there is will be limits set on how many emails can be sent out to try stop it from being used for spamming.  there is a subscribe and a un-subscribe function available.  i know it sounds a bit suspect but if you would like to look at it so you know i not looking on spamming a can let you.

 

once this is built it will be sold to companies who have a need to send out newsletters to there mailing lists.

Link to comment
Share on other sites

Something like this?

 

$sql = "SELECT email_addr FROM merc_users WHERE client = $client";
$res = @mysql_query($sql, $connection) or die("Couldn't get addresses." . $php_errormsg . mysql_error());

$headers = "From: $newsletter_heading.$newsletter_email\n";

while ($row = mysql_fetch_array($res)) {
	$email_addr = $row['email_addr'];

	@mail("$email_addr", $subject, stripslashes($newsletter), $headers);

    	echo "<b>".do_lang("sent_to").": </b> $email_addr<br>";  

}

 

Sends one copy of the newsletter to everyone on the list. Simple enough.

 

Limiting the usage is another matter really. I can't see anyone wanting to send a newsletter to only a proportion of their users so the game will be limiting them to, say, one newsletter a week. Is that what you had in mind or did I misunderstand?

 

 

Link to comment
Share on other sites

thanks for the reply.  yes that was sort of what i wanted.  i just need to add a limit on the amount sent.  i have been reading up on what is allowed and most servers permit 500 (this sounds like spamming again i know but bear with me i am going somewhere with this) messages to be sent out each hour.

 

the problem this system could cause is if there is a company who is lucky enough to have over 500 user registered to there newsletter then once 500 hundred is reached it will stop importing the email address from the list and give the user the message you have reached your limit of allowed emails sent this hour.

 

and once i have sorted this i will have to then try to find out if there is limits on how many can be sent each day, week or month.  i might only allow 500 a day no matter what the limits are.  this way it should stay under any other limits that are imposed on the send messages.

Link to comment
Share on other sites

i have just been speaking to the company who runs are server and they told me only 200 are allowed to be sent out a day through them so it will be dropped down to 200 emails allowed to be sent out a day. 

 

 

 

 

Link to comment
Share on other sites

I guess you need to write something into the database to note who's had which newsletter. How comlex this gets is up to you! I'd put something in like a switch column in the db with values 'y' and 'n'.

 

$sql = "SELECT email_addr,user_uid FROM merc_users WHERE client = $client AND sentto ='n'";

$res = @mysql_query($sql, $connection) or die("Couldn't get addresses." . $php_errormsg . mysql_error());

 

while ($row = mysql_fetch_array($res)) {

 

      $email_addr = $row['email_addr'];

      $usr_uid  = $row['usr_uid'];

 

@mail("$email_addr", $subject, stripslashes($newsletter), $headers);

 

// Change sentto switch for all completed emails

$sql2 = "INSERT INTO merc_users SET sentto  = 'y' WHERE usr_uid = '$usr_uid'";

$result = @mysql_query($sql2, $connection) or die("Couldn't get addresses." . $php_errormsg . mysql_error());

 

}

 

You'll need to add the counter thing into this loop to count your 200 allowed posts but other than that this code *might* work :-)

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.