Hello & Welcome to our community. Is this your first visit? Register

Results 1 to 11 of 11
  1. #1
    Member

    Rank
    Member
    Join Date
    Feb 2009
    Posts
    79

    [MySQL/PHP] Sending email to all email addresses in database?

    Is there any way to "mass" email a message to all of the email addresses stored in my MySQL database? I tried exporting and copying pasting into who I want the email sent to on googlemail, but because some people have put either fake or dud email address, it always tells me "some email addresses are not properly formed/finisehd" you know? It would take me forever to go through and manually edit the "errored/fake" emails :( Any help, advice or info?
    up uP UP

  2. # ADS
    HyperFilter
    RaGEZONE Sponsor

    Rank
      Sponsor  
    Join Date
    Sep 2013
    Posts
    9000


     

  3. #2
    Damn, only 25 characters?

    Rank
    True Member
    Join Date
    Sep 2008
    Location
    127.0.0.1
    Posts
    1,183

    re: [MySQL/PHP] Sending email to all email addresses in database?

    If your hoster accepts fsockopen, use phpmailer(google it :P) to send a confirmation mail, so no fake mails will be made, to confirm the account, add a field to the table, at register time, fill it with a random unique text and send it to the guy mail, make a page that receives it and check if the received hash maches any at db, if it does update account to active.

    You could try to use phpmailer to send the mail too, add the users as CCO and see if it works, I never tested that :\

  4. #3
    :-) s-p-n's Avatar

    Rank
    Alpha Male
    Join Date
    Jun 2007
    Location
    Next Door
    Posts
    2,018

    re: [MySQL/PHP] Sending email to all email addresses in database?

    You know how to send 1 email and store emails in a mysql db, right?

    I also suggest phpmailer() to send the emails. You can also use this to log all of the emails it fails to throw mail at, along with those that worked ;)

    Of course this is how to send the emails to all the users: (change the names accordingly)
    PHP Code:
    $query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database
    while($row mysql_fetch_array($query)) //start a loop to send an email to each individual
    {
        
    //mail function with $row['email'] as the email address
        //I'm using phpmailer as an example here - - >
        
    include_once('phpMailer/class.phpmailer.php');
        
        
    $mail             = new PHPMailer(); // defaults to using php "mail()"
        
        
    $body             $message//message inside the email
        
        
    $mail->From       $from_email//email address that the email is being sent from
        
    $mail->FromName   "Your Company Name"//more in depth for who the mail is from.
        
        
    $mail->Subject    $subject//The subject for the message
        
        //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
        
        
    $mail->MsgHTML($message_html); //HTML version of the message.
        
        
    $mail->AddAddress($row['email'], $row['name']);
        
        if(!
    $mail->Send()) {
          echo 
    '<p>Mailer Error: ' $mail->ErrorInfo .'</p>';
        } else {
          echo 
    '<p>Message sent to: '.$row['name'].' at their email address: '.$row['email'].'!</p>';
        }

    That should work to send the email. You just need to fill in all the blanks:
    $row['name'] and $row['email'] need to apply to your MySQL DB.
    $message, $from_email, $subject, and $message_html need to apply to the email your sending.
    Your Company Name needs to apply to you as well.

    That's it. Hope this helps.

    Oh yeah, don't forget to download phpmailer and upload it to your host. After that, the include should link up fine and it should work. If not, you'll get an error that'll help you out (hopefully)

  5. #4
    Newbie

    Rank
    Member
    Join Date
    Nov 2009
    Posts
    1

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    Quote Originally Posted by s-p-n View Post
    You know how to send 1 email and store emails in a mysql db, right?

    I also suggest phpmailer() to send the emails. You can also use this to log all of the emails it fails to throw mail at, along with those that worked ;)

    Of course this is how to send the emails to all the users: (change the names accordingly)
    PHP Code:
    $query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database
    while($row mysql_fetch_array($query)) //start a loop to send an email to each individual
    {
        
    //mail function with $row['email'] as the email address
        //I'm using phpmailer as an example here - - >
        
    include_once('phpMailer/class.phpmailer.php');
        
        
    $mail             = new PHPMailer(); // defaults to using php "mail()"
        
        
    $body             $message//message inside the email
        
        
    $mail->From       $from_email//email address that the email is being sent from
        
    $mail->FromName   "Your Company Name"//more in depth for who the mail is from.
        
        
    $mail->Subject    $subject//The subject for the message
        
        //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
        
        
    $mail->MsgHTML($message_html); //HTML version of the message.
        
        
    $mail->AddAddress($row['email'], $row['name']);
        
        if(!
    $mail->Send()) {
          echo 
    '<p>Mailer Error: ' $mail->ErrorInfo .'</p>';
        } else {
          echo 
    '<p>Message sent to: '.$row['name'].' at their email address: '.$row['email'].'!</p>';
        }

    That should work to send the email. You just need to fill in all the blanks:
    $row['name'] and $row['email'] need to apply to your MySQL DB.
    $message, $from_email, $subject, and $message_html need to apply to the email your sending.
    Your Company Name needs to apply to you as well.

    That's it. Hope this helps.

    Oh yeah, don't forget to download phpmailer and upload it to your host. After that, the include should link up fine and it should work. If not, you'll get an error that'll help you out (hopefully)
    Hi,

    I have tried the above code and it accepts but I am not receiving any email when I test. Any help?

  6. #5
    The Cat in the Hat cypher's Avatar

    Rank
    Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    5,158

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    Have you ever used phpmail in your webserver? Is it configured?

  7. #6
    Infraction Baɴɴed holthelper's Avatar

    Rank
    Alpha Male
    Join Date
    Apr 2008
    Posts
    1,727

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    dont you need to set up pop3 if use your own computer?

    because i know some hosters provide pop3 when you register.
    why did god curse us with the abilities to make search engines but not give us the knowledge on how to use them?

    Fully(?) working v100 GD Character Image Display for MapleStory - Link
    [PHP] Image to HTML - Link

  8. #7
    Ginger by design.

    Rank
    Developer
    Join Date
    Feb 2007
    Posts
    2,716

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    POP3 isn't related to sending mails

    There are lots of ways to send e-mail via PHP. Sendmail, this method, etc.

    How are you trying to send it? Locally through a locally hosted e-mail, through gmail? You can send via SMTP through sendmail and through phpmail. You're going to need to have something that will relay for you though, however you do it. And then, try relaying a message to a gmail inbox, they don't have super stringent policies on what MX servers they permit to relay mail (like yahoo and others do). As long as your relay isn't blacklisted you should be fine. If you're using gmail through SMTP you should be golden.

    Check out the documentation, I'm too busy to write up code to do it or walk you through it though.
    jmerlin.MSN = "jmerlin[at]jmerlin[dot]net";

    var c = 1; c++ < c; // true

  9. #8
    Member jonapl's Avatar

    Rank
    Member
    Join Date
    Oct 2008
    Posts
    53

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    look up mailbomber in google...

  10. #9
    :-) s-p-n's Avatar

    Rank
    Alpha Male
    Join Date
    Jun 2007
    Location
    Next Door
    Posts
    2,018

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    PHPMailer uses SMTP.

    Did you fill in the From, To, Subject, and Body of the email? PS, this thread is like 9 months old..?

    Oh, more importantly: Did you download and put PhpMailer in the right directory? Enable PHP errors & Warnings and it should show you a fatal error if not..

    Change include_once to require_once.
    Last edited by s-p-n; 30-11-09 at 08:34 PM.

  11. #10
    Member jonapl's Avatar

    Rank
    Member
    Join Date
    Oct 2008
    Posts
    53

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    Quote Originally Posted by s-p-n View Post
    PHPMailer uses SMTP.

    Did you fill in the From, To, Subject, and Body of the email? PS, this thread is like 9 months old..?
    oops sorry :p didnt see it! ill make sure i wont post on old topics again :p rofl

  12. #11
    :-) s-p-n's Avatar

    Rank
    Alpha Male
    Join Date
    Jun 2007
    Location
    Next Door
    Posts
    2,018

    Re: [MySQL/PHP] Sending email to all email addresses in database?

    Quote Originally Posted by jonapl View Post
    oops sorry :p didnt see it! ill make sure i wont post on old topics again :p rofl
    You're fine, it's [Only registered and activated users can see links. ]'s fault.

 

 

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
  •  
HyperFilter
Sponsored by HyperFilter , secured by Incapsula , powered by LiteSpeed.
Mods by DBTech. All times are GMT +1. The time now is 09:59 PM.
Powered by vBulletin® Copyright , Jelsoft Enterprises Ltd.