SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Send email to multiple people

    I made a simple list of people which are all stored into a mysql table.

    How would i make it so that it sends an email to everyone on the list? Also, i know there are some fake emails, if the script encounters one, what will happen?

    I was thinking of just reading each one, throwing a comma after it and use gmail, but there has to be a simpler way.

    Thanks,
    Oleg

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use PHP's mail() function to send the emails. Your code may be something like this:

    PHP Code:
    $sql mysql_query("SELECT * FROM users") or die(mysql_error());
    while (
    $currRow mysql_fetch_array($sql)) {

       
    $from 'youremail@yoursite.com';
       
    $to $currRow['email'];
       
    $subject 'Mail Subject';
       
    $message 'This is a test message';

       
    // Send the mail
       
    if (!(mail($to$from$subject$message"From:$from"))) {
          echo (
    "Error sending email to " $to "<br />");
       } 
    // End IF

    // End WHILE 
    Alternatively, you could get all the email addresses in a single variable separated by ',' and send it like that. However, this means the receiver will be able to see all the other email addresses on the list which isn't necessarily a good thing.

    -Will
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  3. #3
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this will cycle through all of the emails? I never understood arrays.

  4. #4
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it will cycle through each row from your DB table and the mail() function will execute for each user.

    As I say, it could be modified so it only executes once for everybody but I prefer this method.

    -Will
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  5. #5
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the loop works since it kept displaying that it cant send the email.

    I tried to test out so that it just sends it to me but i still get error.

    PHP Code:
       $from 'adsfasdf@wmtoolbox.com'
       
    $to 'sdfsdfs8@gmail.com' //$currRow['email']
       
    $subject 'Todays Top Whore'
       
    $message '
    <p align=\"center\">Todays Top Whore Is:</p>
    <b><a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=27213905\">
    Sexy Kitty</a>
    </b></p>

    <p align=\"center\"><b>
    <a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=27213905\">
    ADD NOW!</a>
    </b></p>

    <p align=\"center\">Want your name and link to be there instead of Sexy Kitty?
     Go to MySpaceAction.com and sign up to compete to be the top whore or the day! 
    Every three days we send this message with the top whore!
    </p>

    <p align=\"center\">

    <a href=\"http://www.myspaceaction.com/?f=0&p=0\">MySpace Action - Spark The Revolution</a></p>'


    echo 
    $message;

       
    // Send the mail 
       
    if (!(mail($to$from$subject$message"From:$from"))) { 
          echo (
    "Error sending email to " $to "<br />"); 
       } 
    // End IF 

    //} // End WHILE 


    ?> 
    Link - www.myspaceaction.com/email.php

    Plus the link turn into www.myspaceaction.com/http://www.myspace.com....

    Why does it do that?

    Regards,
    Oleg
    Last edited by betrollwin.com; Jul 14, 2007 at 08:19.

  6. #6
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    figured out the error with the link, but i still dont get why sending doesnt work.

  7. #7
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump

  8. #8
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two things to consider:

    1- Do you have your SMTP server setup? or, your ISP has that enabled?

    2- SPAM CONTROL, some sites might block sending lots of emails in one shot, reason...well, like I said SPAM. You could pause for a couple of seconds after every email is sent.

    Have you tried to send only 1 email? does it work? if it doesn't then is what I mentioned on point 1, if it does then is point 2.

  9. #9
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not great with the mail() syntax. Try this instead:

    PHP Code:
     $header "From: something@something.com";
       
    $to 'another@another.com' //$currRow['email']
       
    $subject 'Todays Top Whore';
       
    $message '
    <p align=\"center\">Todays Top Whore Is:</p>
    <b><a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=27213905\">
    Sexy Kitty</a>
    </b></p>

    <p align=\"center\"><b>
    <a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=27213905\">
    ADD NOW!</a>
    </b></p>

    <p align=\"center\">Want your name and link to be there instead of Sexy Kitty?
    Go to MySpaceAction.com and sign up to compete to be the top whore or the day!
    Every three days we send this message with the top whore!
    </p>

    <p align=\"center\">

    <a href=\"http://www.myspaceaction.com/?f=0&p=0\">MySpace Action - Spark The Revolution</a></p>'
    ;

    echo 
    $message;

       
    // Send the mail
       
    if (!(mail($to$subject$message$header))) {
          echo (
    "Error sending email to " $to "<br />");
       } 
    // End IF

    //} // End WHILE


    ?> 
    Last edited by LemoNade; Jul 14, 2007 at 11:30.
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  10. #10
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, unexpected T_STRING in /home/rotwyla/public_html/email.php on line 13

    which is:
    PHP Code:
    $to '$currRow['email']'
    double quotes doesnt work either.

  11. #11
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be:
    PHP Code:
     $to $currRow['email']; 
    Like in the previous code ^^
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  12. #12
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by betrollwin.com
    Parse error: parse error, unexpected T_STRING in /home/rotwyla/public_html/email.php on line 13

    which is:
    PHP Code:
    $to '$currRow['email']'
    double quotes doesnt work either.
    It should read:

    PHP Code:
    $to $currRow['email']; 
    Without the quotes around the whole thing.

  13. #13
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    woops.. forgot to take away the quotes... thanks for all your help.

  14. #14
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would you make a pause in between each email sent?

  15. #15
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use:

    PHP Code:
    $secs 4// 4 seconds

    sleep($secs); 


Bookmarks

Posting Permissions

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