This script should send e-mails, which are getting form text file mail.txt and it does it. However I want to do soemthing else, the script should send 10 e-mails after first running. Afterwards, it should should start sending e-mails from 11 to 21 on the list and so on. In the file plik.txt the number of sending e-mails is saved, but i dont know how to force the script to sending e-mails from $i e-mail on the list. Any help? <?php $subject = 'topic'; $message = 'some text'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $key=file('mail.txt'); // text file with the e-mail list foreach ($key as $value) { mail($value, $subject, $message, $headers); if(mail) { $i++; } } $fp=fopen('plik.txt', 'w+'); fwrite($fp, $i); fclose($fp); echo $i; // the numebr of sending e-mails ?> PHP:
May I ask why you would want to split the mailings into groups of 10? You will still have to loop through each 10 to send them individually. You can do it by putting the information to send in an array to send later. Based on what you've already coded this shouldn't be too difficult for you.
This script should start from CRON. Asking about your question, it is server matter. The server doesnt allow me to send more than, let's say 100 e-mail. The second reason is time. On my server i have 30 seconds allowed for scripts execution which for sure will be exceed.
May I know, how your .txt file contains the emails? I mean, how emails are separated from each other in the file?
You could check the file that you write to, to see where the script last got to. Really the best way would be to store everything in a database table. You could then have a column called 'sent' and whenever you sent that message you set that column flag to true. The next time your script runs it only retrieves rows that have not been sent yet.
I dont have permission to do it. Each e-mail in the .txt file is in the new line. It looks like this... email1@.blblbl.com email2@.blblbl.com email3@.blblbl.com PHP: So, the question is how to do it
Copy the complete emails into a text file and use that as the feeder. Send the email to first 10 or 100 email address. Delete them from the file and repeat the procedure in a loop. You may put a sleep in between or else there is a chance that your host/DC may block your Space/Server as potential spammer.
Ah - I'm looking for a similar thing - what a great idea! Add a new column in my table called sent and set it to either 'y' or 'n'. use something like sql(SELECT email, name FROM mailList WHERE sent='n' LIMIT='10') for each mail() set sent to y next PHP: run on a cron job every day - and then you could add in an if statement that says something like: if number of record = 0 then set all 'sent' to 'n' PHP: That way, it would send a block of 10 each day, and when it has run out, it will start the whole process again! Not the best or nicest solution ever, but it does get round all the above problems. If you need a hand writing the PHP or building the MySQL DB for this, give me a shout... I've used really crude scripting here cause I'm in a rush! Take it easy, Andrew EDIT: In real life - my mind works like that! It all makes sense to me- let me know if you need clarification!