Send mail to multiple users

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rahul Dev
Forum Newbie
Posts: 18
Joined: Thu Dec 09, 2010 4:54 am

Send mail to multiple users

Post by Rahul Dev »

Hello, i need to send an email to multiple users. but the problem is that i need to parse a string instead of an array, can any1 help me to solve this problem?
The error is:
Warning: mail() expects parameter 1 to be string, array given in C:\wamp\www\newsletter.php on line 25

my code is:

Code: Select all


$db_hostname="localhost";
$db_username="root";
$db_password="";
$db = mysql_connect($db_hostname,$db_username,$db_password);
if (!$db)
{
	die("Could not connect: " . mysql_error());
}
mysql_select_db("newsletter", $db);

	
if (isset($_POST['categories'])) 
{ //make the checkmarks with name categories[]
	foreach ($_POST['categories'] as $cat) 
	{
		$email_query = mysql_query("SELECT email FROM members WHERE `category` = '" . $cat . "'");

		if (mysql_num_rows($email_query)) 
		{
			while ($email = mysql_fetch_array($email_query)) 
			{
	  
				ini_set('SMTP','smtp.orange.mu');
				if (mail($email, 'Test','This is a test', "From: <noreply@domain.com>"))
				{
					echo "Message Sent";
		
				}
				else
				{
					echo "Message Not Sent";
		
				}
	  
			}//end while
		}// end if
	}
}

User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Send mail to multiple users

Post by Jade »

What format is the $email variable in? For instance, is each email separated by a comma or a semicolon or what?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Send mail to multiple users

Post by yacahuma »

why will you use mail() instead of switmailer?
Post Reply