script for sending mail to all mail address in a text area

Discussion in 'Programming' started by nandanamnidheesh, Oct 19, 2008.

  1. #1
    script for sending mail to all mail address in a text area ?? anyone pls ??:confused:
     
    nandanamnidheesh, Oct 19, 2008 IP
  2. FredL

    FredL Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How are email addresses in textarea formated? If each email is on new line, you could do like this
    
    $subject = 'Test email';
    $mail_body = 'Hello! THis is test mail';
    $header = "From: My Cool Name <mycoolname@mydomain.com>\r\n";
    
    $emails = explode("\n", $_POST['textarea_field_name']);
    if (is_array($emails) && count($emails) > 0) 
    {
      foreach ($emails as $email)
      {
        mail($email, $subject, $mail_body, $header);
      }
    }
    
    PHP:
    Check for more at us.php.net/mail
     
    FredL, Oct 20, 2008 IP
  3. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    but the e-mails are not in each line ...each e-mai address separated by coma
     
    nandanamnidheesh, Oct 20, 2008 IP
  4. Ned

    Ned Active Member

    Messages:
    402
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    78
    #4
    
    $subject = 'Test email';
    $mail_body = 'Hello! THis is test mail';
    $header = "From: My Cool Name <mycoolname@mydomain.com>\r\n";
    
    $emails = explode(",", $_POST['textarea_field_name']);
    if (is_array($emails) && count($emails) > 0)
    {
      foreach ($emails as $email)
      {
        mail($email, $subject, $mail_body, $header);
      }
    }
    
    PHP:
     
    Ned, Oct 20, 2008 IP
  5. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    when dealing with multiple recipients for the same email, it is often best to add the recipient addresses to the $headers for BCC (blind carbon copy), which are hidden from each recipient. That way you only have one open and close connection to the mail server, instead of many.
     
    Bind, Oct 20, 2008 IP
  6. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #6
    ok i let me try now anyway tx FredL, Ned and bind
     
    nandanamnidheesh, Oct 20, 2008 IP
  7. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    but i dint understood what bind saying ??
     
    nandanamnidheesh, Oct 20, 2008 IP
  8. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #8
    friends the script you gave show some errors and i had changed it little bit and it work fine now

    
    <?php
    
    $Name = ""; //senders name
    $mail_body = ""; //mail body
    $subject = ""; //subject
    $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
    
    $recipient = explode(",", $_POST['recipient_list']);
    if (is_array($recipient) && count($recipient) > 0)
    {
      foreach ($recipient as $recipient)
      {
        mail($recipient, $subject, $mail_body, $header); //mail command :)
      }
    }
    
    ?>
    
    
    PHP:
     
    nandanamnidheesh, Oct 21, 2008 IP
  9. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #9
    but i cant use html tags in mail body (like img and <a> tag etc ) anyway ??
     
    nandanamnidheesh, Oct 21, 2008 IP
  10. nandanamnidheesh

    nandanamnidheesh Active Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #10
    "name1" <e-mail1>, "name2" <e-mail2>,

    e-mails are loaded into text area like this way so what all changes should i do in this script ??
     
    nandanamnidheesh, Oct 21, 2008 IP