Jump to content

Recommended Posts

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

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.

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.

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.

  • 2 weeks later...
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.