www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: Read recipient list from file

  1. #1
    Join Date
    Jun 2003
    Posts
    151

    Read recipient list from file

    Well, just a simple question regarding sendmail script.. I wonder how to import recipient list from file???
    This is how default recipient variable looks like:
    $recipient .= "example2@php.net";
    $recipient .= "example3@php.net";

    I don't want to enter emails one at the time like this, but to read them from file. So I guess $recipient variable need to be changed or connected with some other script... Someone told me that it could be done by conecting $recipient with this script, but I don't know how.... Here is that script:
    fgets - Gets line from file pointer
    EXAMPLE:
    $fd = fopen ("/tmp/inputfile.txt", "r");
    while (!feof ($fd)) {
    $buffer = fgets($fd, 4096);
    echo $buffer;
    }
    fclose ($fd);

  2. #2
    Join Date
    May 2003
    Posts
    550
    You could put 1 email address on each line of a text file,
    then set the text file lines to an array using something like
    $emails = file("filename.txt")
    Then $emails['0'] would be the 1st address, $emails['1'] would be the 2nd etc.
    You could use a loop to cycle through them then.

  3. #3
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yeah, do something like what brendandonhue suggested. Put the emails on their own line in a .txt file, and get the values like this:

    PHP Code:
    <?PHP
    $recipient 
    "";
    $contents file("listofemails.txt");
    foreach (
    $contents as $value) {
        
    $recipient .= $value;
    }

  4. #4
    Join Date
    Jun 2003
    Posts
    151
    Why won't this work? I save it as mailer.php and run it through IE on a server(ex. www.server.com/mailer.php), but nothing.. It wouldn't send any emails... And it only has 3 emails in file..

    <?
    $recipient = "";
    $contents = file("emails.txt");
    foreach ($contents as $value) {
    $recipient .= $value;
    }
    $subject = "Subject of the message";

    /* message */
    $message .= "The following email includes a formatted ASCII table\n";
    $message .= "Day \t\tMonth \t\tYear\n";
    $message .= "3rd \t\tAug \t\t1970\n";
    $message .= "17rd\t\tAug \t\t1973\n";

    /* you can add a stock signature */
    $message .= "--\r\n"; //Signature delimiter
    $message .= "My signature";

    /* additional header pieces for errors, From cc's, bcc's, etc */

    $headers .= "From: Od mene <my@email.net>\n";
    $headers .= "X-Sender: <my@sender.net>\n";
    $headers .= "X-Mailer: Microsoft Outlook Express 6.0\n"; // mailer
    $headers .= "X-Priority: 1\n"; // Urgent message!
    $headers .= "Return-Path: <me@emailt.com>\n"; // Return path for errors

    /* If you want to send html mail, uncomment the following line */
    // $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type


    /* and now mail it */
    mail($recipient, $subject, $message, $headers);

    ?>

  5. #5
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    It won't work because once the foreach loop is done, $recipient is going to equal something like "addressone@domain.comaddress2@domain.comaddress3@domain.com" What you are going to want to do is put the entire mail script in the foreach loop, and then set up the recepients like that... Also, concatenating to a string, before you define the variable can cause problems on some servers. ie ($message .= "whatever"; should possibly have a $message = ""; on a line before it)

  6. #6
    Join Date
    Jun 2003
    Posts
    151
    Could you modify my script above, cause I am not very sure how to do what you said... Also, instead of writing $message .= "bla"; for every new line, is it possible to putt only one $message variable and then modify the text and lines from inside quotes? Include that in example too, if it is possible.. Please forgive me for my lack of knowledge..

  7. #7
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try this: (note that I didn't use the form script that you were using, but a varriation of mine, found here)

    PHP Code:
    <?PHP

    ## The lines below need to be edited...

    ###################### Set up the following variables ######################
    #                                                                          #
    $emailfile "file.txt"#file that contains the email addresses
    $subject "Your subject here"#set the subject line
    $message "This is where the email message goes"#your message
    $headers "From: you@your.com"#set the from address
    #                                                                          #
    ##################### No need to edit below this line ######################

    ## mail the message ##

    $contents file($emailfile);
    foreach (
    $contents as $email) {    
        
    mail($email$subject$message$headers);
    }
    echo (
    "Emails successfully sent");

    ?>

  8. #8
    Join Date
    Jun 2003
    Posts
    151
    Something is not right. I think it is with your code... I have 3 emails in my TXT file... First email is not delivered, second one is delivered but there is no FromIt says Nobody) or Subjectit is empty), and in the message box this is written:
    Subject: Your subject here
    From: you@your.com

    This is where the email message goes
    Third email is delivered correct. Everything is the way it should be... But why only third(last) one?????

  9. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    I tested the code before I posted it with 2 email addresses. Please post your modified code. Also, it would be helpful if you attach the file you listed the email addresses in.

  10. #10
    Join Date
    Jun 2003
    Posts
    151
    <?PHP

    $emailfile = "emails.txt"; #file that contains the email addresses
    $subject .= "Subject of the message";
    $message .= "This is where the email message goes"; #your message
    $headers .= "From: Od mene <moj@email.net>\n";

    $contents = file($emailfile);
    foreach ($contents as $email) {
    mail($email, $subject, $message, $headers);
    }
    echo ("Emails successfully sent");

    ?>
    Attached Files Attached Files

  11. #11
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try setting these:

    PHP Code:
    $subject .= "Subject of the message"
    $message .= "This is where the email message goes"#your message 
    $headers .= "From: Od mene <moj@email.net>\n"
    to these:

    PHP Code:
    $subject "Subject of the message"
    $message "This is where the email message goes"#your message 
    $headers "From: Od mene <moj@email.net>\n"

  12. #12
    Join Date
    Jun 2003
    Posts
    151
    Nope, now it sends messages to all three emails, but only the LAST ONE from the list gets email in proper way... Other two get this... I used authentical code that is written last time...
    From field: Nobody Subject: Empty Space
    Subject: Subject of the message
    From: Od mene <moj@email.net>


    This is where the email message goes
    All this is writtn in the message window...
    I don't know... Try to upload to your server and execute the same script with same emails.. Maybe it is an error in my ISP sendmail() configuration.. Just change the Subject so I know that it is you....

  13. #13
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Ok, I ran it from my server...

  14. #14
    Join Date
    Jun 2003
    Posts
    151
    Yap, I got all in perfect order.... So it gotta be my ISP's cofiguration error... Any way to fix this or use some other mailing program? This is my free space I was given with dialup. Is there a way to check if the right mailing program is installed?????
    Anyway, more important now that everything is working... Is there a way to make a log file after the emailing has been done, that will log SENT and UNSENT emails...
    Or, cool feature, but I don't think that this can be done... When sending, a popup window pops up(offcourse) and says
    sending email 1 of 983
    and changes as the email is sent... That is a cool way to find out a speed of sending...
    Last edited by Kor; 04-14-2008 at 03:57 AM.

  15. #15
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, must be a problem with the server, though a weird one, at that.

    Depends on what you mean by "keep a log of sent email." You certainly could log each email that the PHP sends a message to, but I'm not aware of a way to check if the email bounced or not...

    And, as far as telling you which email it is on, you'd be able to do it (though I'm not sure about in a popup). But, it might be to fast to really see anything...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles