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: <noreply@domain.com>"))
			{
				echo "Message Sent";

			}
			else
			{
				echo "Message Not Sent";

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.