Sending emails !!

Discussion in 'PHP' started by ausgezeichnete, Dec 8, 2007.

  1. #1
    I have a form that conatins teh field
    and its inserted into the database

    now if i want to send mail to all who has checked it
    i did so but couldnt complete it
     
    ausgezeichnete, Dec 8, 2007 IP
  2. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    
    $querystr = mysql_query("SELECT * FROM wsd_members WHERE promos=1";);
    
    PHP:
    This isn't so optimized, query will take longer, but should work. On your code, query wasn't executed, and if was executed, to all the members was going to send the email, because == 1 is similar to == true (I think, even if 0 still true, value existed).
     
    hip_hop_x, Dec 8, 2007 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    The mail() function needs to have 3 mandatory parameters.

    You can't just do mail();

    
    mail($to, $subject, $message);
    
    PHP:
     
    Kaizoku, Dec 8, 2007 IP
  4. ausgezeichnete

    ausgezeichnete Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thnxx,i did so but i cant try it cuz am working on localhost
     
    ausgezeichnete, Dec 9, 2007 IP
  5. ausgezeichnete

    ausgezeichnete Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i did so but i cant try it cuz am working on a localhost
    is this ok??
    
    mysql_select_db($database_trial, $trial);
    $query_Recordset1 = "SELECT email FROM wsd_members where promos='1'";
    $result=mysql_query($query_Recordset1);
    if(!$result)echo mysql_error();
    while($records=mysql_fetch_array($result)){
    $sender="maha@maha.com";
    for($i=0;$i<count($records);$i++)
    mail($records[$i],$subject,$msg,$sender);
    }
    
    
    PHP:
     
    ausgezeichnete, Dec 9, 2007 IP
  6. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #6
    The 4th parameter is the headers. You need to do something like this

    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    // Additional headers
    $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
    $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
    $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
    $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
    
    mail($records[$i],$subject,$msg,$headers);
    
    PHP:
     
    Kaizoku, Dec 9, 2007 IP
  7. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #7
    Dont forget the reply-to header otherwise the mail may not be send
     
    buldozerceto, Dec 9, 2007 IP