Submit form to multiple emails?

Discussion in 'PHP' started by mandkr67, Dec 29, 2005.

  1. #1
    I have a php form that a client needs to get the emails to 3 or 4 people. If in the form is

    $mailto = 'rchichester@gmail.com' ;
    Code (markup):
    can I add more addresses to this string, and do I need to add the single quotes around each one or around the lot of them?
     
    mandkr67, Dec 29, 2005 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want the emails to be different, you can create new vars, $to and $to2

    with $body and $body2

    If you want the same email, all To not CC, or BCC

    Then simply add another var

    $mailto = 'email@email.com' . "\r\n".
    $mailto = 'email2@email.com' . "\r\n".
    $mailto = 'email3@email.com';

    I always suggest testing things like this, before giving it to the boss man.
     
    onlyican.com, Dec 29, 2005 IP
  3. mandkr67

    mandkr67 Peon

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, the emails will all be the same just to 3 different people. I'll give that a try. Thanks!

    Now I have to wait for the 2 other emails to be set up. Why can't everyone just use Outlook...;)
     
    mandkr67, Dec 29, 2005 IP
  4. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Instead, I would probably simply put the email addresses into an array, and then loop through the array, calling mail() once for every email address. There are several ways to do this, though...
     
    Nathan Malone, Dec 30, 2005 IP
  5. pwaring

    pwaring Well-Known Member

    Messages:
    846
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    135
    #5
    I'd strongly recommend using multiple addresses in either the To, Bcc or Cc fields rather than calling the mail() function several times. There's absolutely no point in calling mail() for every single email address if the message is going to be the same, just put all the recipient addresses in whichever field suits you best (e.g. Bcc if you don't want anyone to know who else the email has been sent to) and your mail server will transform that into the right number of individual messages. Don't do something in PHP if the mail server can do it for you (and probably a lot faster too).
     
    pwaring, Dec 30, 2005 IP