Page 1 of 1

Send mail to multiple users

Posted: Sun Jan 23, 2011 6:51 am
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
	}
}


Re: Send mail to multiple users

Posted: Sun Jan 23, 2011 2:08 pm
by Jade
What format is the $email variable in? For instance, is each email separated by a comma or a semicolon or what?

Re: Send mail to multiple users

Posted: Sun Jan 23, 2011 3:46 pm
by yacahuma
why will you use mail() instead of switmailer?