how do i achive this email from database

Discussion in 'PHP' started by dougvcd, Feb 22, 2008.

  1. #1
    can any one tell me how to do this
    i want to email all members in my database like a news letter
    but dont know where to begin
    any help please
    cheers
    Doug
     
    dougvcd, Feb 22, 2008 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Have you already got them stored in a database?

    You can use a while query to loop out the emails something like this,

    
    $result = mysql_query("SELECT * FROM `table_name`");
    $total = @mysql_num_rows($result);
    
    $i=0;
    
    while($i<$total)
    {
    $email = mysql_result($result, $i, 'email');
    $name = mysql_result($result, $i, 'name');
    mail($email, 'Subject', "Message here", $headers);
    echo "<p>Sent email to $name, email: $email ok.</p>";
    $i++;
    }
    
    PHP:
    Change the tables and collum names ot match your own database but that's a rough guide on looping out results from a database.
     
    HuggyStudios, Feb 22, 2008 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for that but is there a way to attach a newsletter or incorparate it some where
    cheers
    Doug
     
    dougvcd, Feb 22, 2008 IP