Jump to content

sending mail array problem


Rahul Dev

Recommended Posts

Hello, i need to send emails to users according to the category they have selected everything works fine except for the mail function which tells me that i cannot parse an array variable. the error code is:

Warning: mail() expects parameter 1 to be string, array given in C:\wamp\www\newsletter.php on line 25

 

can any1 tell me how i can send the mail so that it accepts that variable?

my code is:

 

<?php
$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.gmail.com');
			if (mail($email, 'Subject','Message Goes Here', "From: <[email protected]>"))
			{
				echo "Message Sent";

			}
			else
			{
				echo "Message Not Sent";

			}
  
		}//end while
	}// end if
}
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/225410-sending-mail-array-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.