Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    mail function with list inside text file

    I have a few text files that include a few hundred email addresses each separated by new lines. I need to use the mail() command to send a separate email to each email. I know how to do this using a database, but I can't figure out how to with fopen(), if that's even what i'd use. Anyone know how this could be done?

    PS: The code below is what I use for a database, need something that does the same with a text file.

    PHP Code:
    $result mysql_query("select * from users order by uId");
    //grab all the content
    while($r=mysql_fetch_array($result))
    {    
       
    $send=$r["email"];

    if (
    $error == "") {
    mail($send,$subject,$body,"From:$aemail\nContent-Type: text/html; charset=iso-8859-1");

    echo 
    "<div align=center>email sent to:$send<Br></div>"

  • #2
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Try this:
    PHP Code:
    <div align="center">
    Email sent to:<br>
    <?php
    $list 
    file('email-list.txt');
    foreach(
    $list as $email)
    {
        
    mail($email$subject$body"From:$aemail\r\nContent-Type: text/html; charset=iso-8859-1");
        echo 
    "$email<br>";
    }
    ?>
    </div>

  • #3
    New Coder
    Join Date
    Nov 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much! The code works perfectly, you are truly a life saver =]


  •  

    Tags for this Thread

    Posting Permissions

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