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 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending email to multiple persons

    Hi,Iam new to PHP.

    I know how to send the email for a single person,Iam using SMTP server,now I want to send a email to a multiple persons at a time.Please help me how to code for this.Please send 1 example.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Use an array to make a list of the e-mails(or use a comma-delimited string and explode() it) and then use foreach() to loop through them, sending the message to each person.
    Something like this:
    PHP Code:
    $emails = array('first@email.com','second@email.com');
    foreach(
    $emails as $addr)
    {
        
    // mail($addr, 'subject', 'message');


  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    If there isn't any privacy iissue with showing all the recipient names at the top of the email then you can supply all the addresses in the one field as a comma separated list.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    That's true, or you could even do a BCC with the headers. I had forgotten about that.

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Smile

    You should use a MySQL DB, to store all the emails. Then Send them to the required addresses as necessary.

  • #6
    New Coder
    Join Date
    May 2005
    Location
    Leeds, UK
    Posts
    83
    Thanks
    1
    Thanked 0 Times in 0 Posts
    how many people are you sending to? And will the content change for each recipient (eg having their name in the mail).

    The mail() function is pretty clunky and can slow up a server, so if you need to send a lot of emails at once then you might want to try an external class like swiftmail.


  •  

    Posting Permissions

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