zdiver Posted May 9, 2007 Share Posted May 9, 2007 Hello I'm looking to have a form emailed to a list of users one at a time in rotation. 1,2,3,4,5,1,2,3... etc. Can this be accomplished without using a database? Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/ Share on other sites More sharing options...
Ninjakreborn Posted May 9, 2007 Share Posted May 9, 2007 Depends, if you KNOW who they are you can just use an "array" of all the email addresses. You can always use flatfile, or csv. Another thing I would keep in mind, if you are going to be doing Mass Mails, you probably want to avoid using "just" php. What the www.php.net website recommends http://us.php.net/manual/en/function.mail.php They recommend the "http://pear.php.net/package/Mail_Mime" package. I personally recommend the "phpmailer" class located at phpmailer.sourceforge.net Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-249402 Share on other sites More sharing options...
zdiver Posted May 9, 2007 Author Share Posted May 9, 2007 Yes, I will know who they are. It's a small firm that is adding sales reps and wants to email a senior rep in addition to parse out sales to new reps one at a time. I've never really used an array before so pardon my lack of knowledge here. If I were to use an array, would it be able to keep track of where it is in the rotation? $name=array("a"=>"john@abc.com","b"=>"bill@abc.com","c"=>"mike@abc.com"); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-249418 Share on other sites More sharing options...
zdiver Posted May 10, 2007 Author Share Posted May 10, 2007 bump Anybody know how I can make the array keep track of it's position in the rotation between each submission of the form? Much appreciated, Chuck Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-250115 Share on other sites More sharing options...
per1os Posted May 10, 2007 Share Posted May 10, 2007 www.php.net/array www.php.net/current www.php.net/each www.php.net/prev www.php.net/next Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-250127 Share on other sites More sharing options...
Psycho Posted May 10, 2007 Share Posted May 10, 2007 An array in and of itself won't really help you - what is important is saving the data. In this case you need to use a flat file. Create a text file with all of your email addresses in it separated by a semicolon - DO NOT put a semicolon after the last email address (you can enter line breaks if you wish): email_list.txt me@here.com; you@there.com; he@she.net; someone@somewhere.org Now, on the page that you need to get the new email address include this function "getEmail()" and be sure to put the file name and path to the data file for the $emailFile variable. Now you can get the next email in the list each time using something like this: $email = getEmail(); testEmail.php <?php function getEmail() { //Define the data file to use $emailFile = "email_list.txt"; //Open the data file and get the contents $fh = fopen($emailFile, 'r'); $email_string = fread($fh, filesize($emailFile)); fclose($fh); //Create an array $email_array = explode(';', $email_string); //Pop off 1st email and define the new email $new_email = trim(array_shift($email_array)); //Push the 1st email to the end of the array array_push($email_array, $new_email); //Convert email array back to a string $email_string = implode(';',$email_array); // Write the new list back to the data file $fh = fopen($emailFile, 'w') or die("can't open file"); fwrite($fh, $email_string); fclose($fh); //Return the new email return $new_email; } $email = getEmail(); echo $email; ?> Put the two files above in the same directory and run testEmail.php through your browser. Each time you refresh you will get the next email address in the list and it will loop when it gets to the end. Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-250169 Share on other sites More sharing options...
zdiver Posted May 14, 2007 Author Share Posted May 14, 2007 That works FANTASTIC. Wonderful comments throughout and an easy example for the test, so thank you mjdamato! For some reason the server(windows) would only accept a relative path for the flat file but that's good enough for me. Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-252897 Share on other sites More sharing options...
Psycho Posted May 14, 2007 Share Posted May 14, 2007 Well, I was pretty sure that was exactly what you wanted and was wondering if you would ever post back! One word of caution though. When I was putting it together I had some errors in the reading part of the script and that caused the new file to be blank. Now, chances are you may never encounter an error, but just in case you should probably have a backup file of your email list just incase the original gets blanked. If I was going to use this for my own purposes i would add some more error handling. Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-253047 Share on other sites More sharing options...
zdiver Posted May 24, 2007 Author Share Posted May 24, 2007 OK, thanks for the advice. I have had an issue with it erasing one user from a list of two. Any thoughts on the error handling part? If I were to were to make a backup before and after and compare them, would that work? Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-260939 Share on other sites More sharing options...
Psycho Posted May 24, 2007 Share Posted May 24, 2007 Can you provide an example of the list items that are causing the problem? I'm not sure I understand - are you wanting to have two recipients treated as one? Quote Link to comment https://forums.phpfreaks.com/topic/50729-email-in-rotatation-to-a-list-of-users/#findComment-261040 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.