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

Thread: Read from TXT instead MYSQL

  1. #1
    Join Date
    Jun 2003
    Posts
    151

    Read from TXT instead MYSQL

    I must post this thread in a new post because the last one where I mentioned this has jumped of the subject and no one is responding... Anyway, found this script that has everything I need.. It has option to limit how many emails will be sent at once, and therefore timeout will not occur. Then, it logs how many messages are sent, but has one "fault".. It reads a list of recipient from SQL database... I need it to read a list from a regular text file... Here is the script that needs to be modified...
    <?php

    $host = "localhost"; //Host
    $user = ""; //Username
    $pass = ""; //Password
    $database = ""; //Database name
    $table = ""; //Name of table that has list of emails
    $column = ""; //Name of column in table that has list of emails
    $num_per_loop = "5"; //Number of emails sent per page loop (keep number low to avoid page time-out)
    $from_name = "Jason Rottman (Developer)"; //Reply address email address
    $from_email = ""; //Name the emails came from
    $mail_subject = "This is the subject of the message";
    $mail_body = "This is the body of the message (you can use html)";
    $send_html_messages = "yes"; //yes - Send html messages, no - Do not send html messages
    //////////////////////////////////////////////////////////////////////////////
    // DO NOT CHANGE ANYTHING BELOW THIS LINE //
    //////////////////////////////////////////////////////////////////////////////


    if (($first_time == "yes") || ($first_time == "")) {
    $total_sent = "0";
    $total_time = "0";

    $start = "0";
    $num_to_end = $num_per_loop;
    }
    if ($first_time == "no") {
    $start = $start;
    $num_to_end = $num_per_loop;
    }

    $mydb = mysql_connect($host,$user,$pass);
    if (!$mydb) { echo "Error connecting to database"; die; }
    mysql_select_db($database);

    $varx = $start + $num_to_end + 1;
    $result2 = mysql_query("SELECT " . $column . " FROM " . $table . " LIMIT " . $start . ", " . $varx . "") or die(mysql_error());
    $num_left = "0";
    $clock_start = number_format(microtime(),3);
    while(list($email_addr) = mysql_fetch_row($result2)) {
    $num_left = $num_left + 1;
    }
    $result3 = mysql_query("SELECT " . $column . " FROM " . $table . " LIMIT " . $start . ", " . $num_to_end . "") or die(mysql_error());
    while (list($column) = mysql_fetch_row($result3)) {

    $xheaders = "From: " . $from_name . " <" . $from_email . ">\n";
    $xheaders .= "X-Sender: <" . $from_email . ">\n";
    $xheaders .= "X-Mailer: PHP\n"; // mailer
    $xheaders .= "X-Priority: 6\n"; // Urgent message!
    if ($send_html_messages == "yes") {
    $xheaders .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
    }
    mail("$column",
    "$mail_subject",
    "$mail_body",
    $xheaders);
    $total_sent = $total_sent + 1;
    }
    $clock_stop = number_format(microtime(),3);
    $clock_difference = $clock_stop - $clock_start;
    $total_time = $total_time + $clock_difference;
    mysql_close();


    if ($num_left > $num_per_loop) {
    $next_start = $start + $num_per_loop;
    //echo "<a href=\"" . $PHP_SELF . "?first_time=no&start=" . $next_start . "&total_sent=" . $total_sent . "&total_time=" . $total_time . "\">Next " . $num_per_loop . "</a>\n";
    header("Location: " . $PHP_SELF . "?first_time=no&start=" . $next_start . "&total_sent=" . $total_sent . "&total_time=" . $total_time . "");
    }
    if ($num_left <= $num_per_loop) {
    echo "FINISHED<br><br>";
    echo "Total Emails Sent: " . $total_sent . "<br>\n";
    echo "Total Script Run Time Used: " . $total_time . " seconds<br>\n";
    echo "<a href=\"" . $PHP_SELF . "\">Run Again</a><br><br><br>\n";
    echo "Provided By: <a href=\"http://www.rottmansales.com/jason/\">http://www.rottmansales.com/jason/</a><br>\n";
    end;
    }

    ?>
    I tryed inserting this code
    $contents = file($emailfile);
    $num_lines = count($contents);
    instead of the part wher it reads emails from SQL, and I deleted uneccessary parts, but I get errors. I probably deleted too much, or too little... Can you post the whole script valid?
    Last edited by Extreme; 07-05-2003 at 06:30 AM.

  2. #2
    Join Date
    May 2003
    Posts
    225

    from looks...

    from the looks of your script, it looks as if you are trying to e-mail someone. can you explain what it does?

  3. #3
    Join Date
    May 2003
    Posts
    225
    never mind...
    I found out what t does!
    It is a mass mailer!

    alright... I am working on it!

  4. #4
    Join Date
    May 2003
    Posts
    225
    err--- a little too much for me.

  5. #5
    Join Date
    Jun 2003
    Posts
    151
    Sorry I didn't reply sooner. Didn't see that you replyed... Well, it is a mass mailer, but very special one.. It is simple and yet, has everything I need: read recipients from file, prevention of timeout, statistics on sent mails... But, since I don't have SQl on my server, nore I know anything about it, the script must be changed so it reads recipients from TXT.. Also, it would be good if you could make some kind of form that will have BROWSE button and SEND button... BROWSE would be use to locate TXT file with email recipents....

  6. #6
    Join Date
    Jun 2003
    Posts
    151
    This is a code to read emails from txt file...
    $emailfile = "emails.txt"

    $contents = file($emailfile);
    $num_lines = count($contents);

    mail($emailfile, ......)

    Maybe it will help.... The biggest problem for me is to eject uneccessary SQL part....

  7. #7
    Join Date
    May 2003
    Posts
    225
    I try to do my best, but I only just got startrd with PHP!
    Well, this script is unique, because it refreshes the page every 5 e-mails.

    i would not know how to do that...

    mabye use the foreach() method and translate it to an array...

    here is a script I made that uses that example to remove coments from a .txt file.

    *opps* forgot to post the code

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>comments</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <p><code title="commented-out code">
      <?PHP

    $config 
    file('index.txt'); // URL of the config file
    foreach ($config as $inc) { 

    $note   '#';
    $pos strpos($inc$note);
    if (
    $pos === false) {// not found
    $included $inc;
    echo 
    $included "" ;

    }else{
    // found

    $to_include substr($inc0$pos);// trim comments
    echo $to_include "";

    }
    echo 
    "<br>\n";

    }

    ?>
      </code><br>
      And here is is the REAL file... <br>
      <a href="index.txt">(link to the .txt file)</a><br>
      <a href="source.txt">(source code)</a><br>
      <br>
      <code title="the REAL code"> 
      <?php

    foreach ($config as $inc2) { 
    echo 
    $inc2;
    echo 
    "<br>\n";
    }
    ?>
      </code> </p>
    </body>
    </html>

  8. #8
    Join Date
    May 2003
    Posts
    225
    this script converts a .txt file into a array...

    PHP Code:
    <?php
    $config 
    file('mail.txt'); // URL of the config file
    $email = array();
    $i 0;
    foreach (
    $config as $inc) { 
    $email[$i] = $inc;
    $i++;
    ?>
    and I also found this at http://www.atomar.de/public/code/deb...uglib.demo.php(it was a link submitted onto www.php.net)

  9. #9
    Join Date
    Jun 2003
    Posts
    151
    No need for that... My code I gave above works the same way, with less lines.. But the original problem was how to insert this into the code from the begining of the post, and ejecting all SQL related without getting errors... and getting script to work offcourse...

  10. #10
    Join Date
    May 2003
    Posts
    225
    Well... If you cannot know what line of the file you are on, you cannot start from a spacific point in the file. If you convert it into an array, than you can figure out what line it is on. Why would you want to start on a single line? because PHP may take too long and time out, so you want to refresh every once in a while.

    Oh, that script I had a link to shows variables when you call the right function. I use it to see if I have made an array correctly.


    PHP Code:
    <?php
    $config 
    file('mail.txt'); // URL of the config file
    $email_a '';//your email
    $email_n '';// your name
    $msg_timeout '';
    $subject '';//the subject of the message.
    $body "
    Body here. You can include HTML if you have set it,
    otherwise it is a text message
    "
    ;

    $email = array();
    $i 0;
    foreach (
    $config as $inc) { 
    $email[$i] = $inc;
    $i++;
    ?>
    Oh just to let you know, this is not finished

    P.S. do you want to type the body of the message into a text file, too? I can do that!
    Last edited by diamonds; 07-10-2003 at 05:12 PM.

  11. #11
    Join Date
    May 2003
    Posts
    225
    Originally posted by Extreme
    ...prevention of timeout,...
    Oh... you allredy said you wanted it (silly me)
    Originally posted by Extreme
    ...since I don't have SQl on my server...
    You don't have MySQL?Is a company hosting your server, or are you running one yourself? I could help you install it

  12. #12
    Join Date
    Jun 2003
    Posts
    151
    My english is not serving me that well, so I don't know what does mean "array"... My code reds one email at the time from TXT and eveery email is in a new line... Your's does the same thing or better??????
    IN the first script I wrote upp there, there is a functon that prevents timouts, because it doesn't allow server to send more than certain number of messages at once(I think)...
    I don't have money to buy a server so I must use my free webspace I got with dialup account.... And therefore, I have no SQL, and way to install it...
    Last edited by Extreme; 07-11-2003 at 11:47 PM.

  13. #13
    Join Date
    May 2003
    Posts
    225
    Well, an array is somthing where you can store multiple variables in one variable.

    Try this script on your server:
    PHP Code:
    <?php
    $see_me 
    = array(
    '77',
    '66',
    '55',
    'a' => '678',
    'b' => '123'
    );

    echo 
    $see_me[1]."<br>\n";
    echo 
    $see_me[2]."<br>\n";
    echo 
    $see_me[3]."<br>\n";
    echo 
    $see_me['a']."<br>\n";
    echo 
    $see_me['b']."<br>\n";
    ?>
    also search php.net for the array() function.

    http://us3.php.net/manual/en/ref.array.php
    http://us3.php.net/manual/en/function.array.php

  14. #14
    Join Date
    Jun 2003
    Posts
    151
    OK, so there is a code for reading email list from file..
    Now all "we" need to do is to replace SQL code with that one.. It is a bit tricky for me to do it, because there are many variables that can't be just deleted..
    CAn someone try to make changes without destroying these valuable options like timeout prevention and echoing the email sent..

  15. #15
    Join Date
    May 2003
    Posts
    225
    Ahhh! you replyed!
    (i thought you didnt like this forum anymore)

    the header would go somthing like this:
    PHP Code:
    <?php
    $most_to_mail 
    5;
    $curr = @$_GET['curr'];
    if(
    $curr == ""){$curr 0;}
    $list file('maillist.txt');


    for(
    $i=$curr,$curr>=count($list),$i++){
    mail($list[$i]);
    }
    ?>
    I continue to work on it.

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