SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys -

    I desparately need a simple PHP script that will do the following:

    1) Read an email address from a simple text file - each email address is on a separate line
    2) Send an email (pre-defined message by me) to all these users

    There are about 5,000 email addresses in the list. (Hopefully this will not slow the system down). I currently have a Perl script for this, but it often results in the process timing out on the server - someone suggested using PHP instead.

    I've been told this is a fairly simple script, but having just started PHP I don't have the time/patience/whatever(!) right now to work on this.

    So if someone could write me this script I'd highly appreciate it. Thanks!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I won't write you the whole script, cause you won't learn that way. But here is a start

    <?
    $from = "From: youremail@yoiurdomain.com\r\n";
    $subject = "This is the subject";
    $body = "This is an email";
    $textfile = "email.txt";
    $data = file($textfile);
    foreach($data as $val) {
    mail($val, $subject, $body, $from);
    }

    ?>


    That was the basics for sending the emails. Now you will probably need to change the max execution time for the script to get all the emails sent out.

    For Apache:
    Put a file called .htaccess in the folder where this script will live and add the following line to it
    php_value max_execution_time 180

    Make sure not to have any blank lines in the file. ANd 180 is the number of seconds that the script has to complete. By default this is set to 30 in the php.ini file.


    For IIS on windows make the change in thephp.ini file.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thank you so much!

    Well, yeah, I've been putting off learning it properly for a while now - primarily because this is my final semester, and I need to graduate!

    Anyway, few qucik questions:

    1) Do I just fill up the body variable with my email? Can it be so that the email is read from a text file instead - i.e. with some newline formatting and all inside it?
    (I'll look this up, just wanna know if its do-able i.e. easily!)

    2) Would hotscripts have a script that checks for duplicate email addresses in the file, and removes them until only one entry is left?
    (The text file's structure should remain intact i.e. each email address on a separate line)

    Thanks again freddy. I'll tweak your code around a bit and mess around with some temp. email addresses before I start mailing the users.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    totally possible.
    $template = "template.txt";
    $fp = fopen($template);
    $body = fgets($fp, filesize($template));
    fclose($fp);
    //Now $temp has the email message


    to take the duplicates out just do
    $data = array_unique($data);
    Before looping through the array
    //Right after
    $data = file($textfile);

    //Put it Here
    $data = array_unique($data);

    //put it right before
    foreach($data as $val) {
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot
    Join Date
    May 2000
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a script that ran for a few minutes... which timed out always.

    I just modified it to print the status every 10 seconds or so... That solved the problem.

    For example, just modify your perl script to print out the number of emails sent...

    ex:
    100 of 5000
    200 of 5000
    .
    .
    .
    5000 of 5000

    That should be a simple solution!

    Regards,

  6. #6
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm freddy...

    I tried the code you sent me..but got some weird results.

    1) My template.txt file contained lots of newline characters, and lines with text etc. but the message set only contained the first line of template.txt

    2) The mail did not go to all the users. Instead it was sent only to my address - i.e. the one I am registered at with the hosting service...So all the emails from the test email.txt file got sent to me at my default address at the host.

    3) The array unique command did not detetct name@email.com and NaMe@emaiL.com as the same address.

    Any help would be appreciated.

    Thanks!

    p.s. I'm going to look up some tutorial on the Net for this to understand this better. Hope to hear from you soon!

  7. #7
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correction:

    freddy, I did receive the email at the other email addresses in the email.txt file, but they all received multiple emails (I think just as many as there were email addresses), and only the first line showed up...Hmm..!

    Arpit: Thank you for the suggestion. I'm tempted to try making that change to the Perl script, however, I have 5000 legit emails in that file, and I really don't want to risk not having this work - multiple emails to the website users could really piss 'em off!

    Thanks!

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you did the array_unique thinkg right? You do have php4 right? Post the code again.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Zealot zeeshan's Avatar
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy -

    Posted below is the code for newsletter.php

    <?
    $from = "From: youremail@yoiurdomain.com\r\n";
    $subject = "This is the subject";

    $template = "template.txt";
    $fp = fopen($template, "r");
    // I put the "r" bit in, cuz it said parameters were missing

    $body = fgets($fp, filesize($template));
    fclose($fp);

    $textfile = "email.txt";
    $data = file($textfile);

    $data = array_unique($data);

    foreach($data as $val) {
    mail($val, $subject, $body, $from);
    }

    ?>


    Here's the templates.txt file

    Dear visitors,

    What do we have for you in this update?
    ---------------------------------------

    !
    @
    $
    ~ kjfkdf
    ~ kjfkldjf

    * dfj

    To unsucscribe http://www.url.com/unsub/



    And here's the email.txt file with all the email addresses

    zeesh@something.com
    zeeshan@somethingelse.com
    info@something.com
    Zeesh@something.com (again)
    mea@uni.edu
    MeA@uni.edu (again)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •