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

Results 1 to 11 of 11
  1. #1
    Account Inactive CherryPop is offline
    InactiveRank
    Feb 2009 Join Date
    79Posts

    [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?


  2.  
  3. #2
    Account Inactive BBim is offline
    InactiveRank
    Sep 2008 Join Date
    127.0.0.1Location
    1,183Posts

    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 is offline
    Alpha MaleRank
    Jun 2007 Join Date
    Next DoorLocation
    2,050Posts

    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)
    If you like my content here, please comment on my blog.

  5. #4
    Account Inactive dhrisht is offline
    InactiveRank
    Nov 2009 Join Date
    1Posts

    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 is offline
    ModeratorRank
    Oct 2005 Join Date
    IrelandLocation
    5,217Posts

    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 is offline
    Alpha MaleRank
    Apr 2008 Join Date
    1,726Posts

    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. jMerliN is offline
    DeveloperRank
    Feb 2007 Join Date
    2,710Posts

    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
    Account Inactive jonapl is offline
    InactiveRank
    Oct 2008 Join Date
    53Posts

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

    look up mailbomber in google...

  10. #9
    :-) s-p-n is offline
    Alpha MaleRank
    Jun 2007 Join Date
    Next DoorLocation
    2,050Posts

    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
    Account Inactive jonapl is offline
    InactiveRank
    Oct 2008 Join Date
    53Posts

    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 is offline
    Alpha MaleRank
    Jun 2007 Join Date
    Next DoorLocation
    2,050Posts

    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 dhrisht's fault.


  13.  

    Latest Gaming Releases

Advertisement