Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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

Initiate Mage
Joined
Feb 23, 2009
Messages
24
Reaction score
0
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?
 
Divine Celestial
Member
Joined
Sep 13, 2008
Messages
853
Reaction score
14
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 :\
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
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:
$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) :thumbup1:
 
Initiate Mage
Joined
Nov 29, 2009
Messages
1
Reaction score
0
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:
$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) :thumbup1:

Hi,

I have tried the above code and it accepts but I am not receiving any email when I test. Any help?
 
Infraction Baɴɴed
Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
dont you need to set up pop3 if use your own computer?

because i know some hosters provide pop3 when you register.
 
Ginger by design.
Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
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.
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
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:
Initiate Mage
Joined
Oct 19, 2008
Messages
51
Reaction score
0
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
 
Back
Top