954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

send email on mysql db update

i am trying to write a script that will send out an email to all the email addresses stored in a mysql db when the site has been updated. the code i have so far is as follows

$sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  $lastid = mysql_insert_id();
  
  $message .= '<body leftmargin="0" topmargin="0">
	<table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
    <tr>
		<td>The ' . $table . ' section of the <a href="piponline.info"> PiPonline website</a> has been updated.  Please follow the link to see the new content.
	</tr>
  </table>
  </body>';


	$query = "SELECT email FROM emails";
	$result = mysql_query($query) or die(mysql_error());

	while($row = mysql_fetch_array($result)){
	$contactemail = $row['email']. ", ";
	}



	// Contacts
	//$replyName = $merc_replyId;
	//$replyEmail = $merc_replyAddress;
	
	$replyName = "PiPonliine";
	$replyEmail = "info@piponline.info";

	$contactname = "";
	

	// Subject
	$subject = "Website Update";

	// Headers
	$headers = "MIME-Version: 1.0" . PHP_EOL;
	$headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
	$headers .= "From: ".$replyName." <".$replyEmail.">\r\n" . PHP_EOL;
	$headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
	

	mail(implode(',', $contactemail), $subject, $message, $headers);
  echo "$contactemail";
  echo "<h2>Email notification sent</h2>";
  echo "<h2>1 record added</h2>";

  mysql_close($con);


this code is giving me the following error message which as far as i know means that array is not being populated.

Warning: implode(): Bad arguments


due to the error the emails are not being sent even if the code for that section is correct or not.

kevin wood
Posting Whiz
347 posts since Feb 2008
Reputation Points: 27
Solved Threads: 1
 

i have changed the code slightly now and have got it sending out one email. i have narrowed the problem down to the mysql query as this is not populating the array it is only putting on email address in.

here is the code for the mysql statement

$query = "SELECT email FROM emails";
	$result = mysql_query($query) or die(mysql_error());

	while($row = mysql_fetch_array($result)) {
	
	$contactemail = $row[0]. ", ";
	}
kevin wood
Posting Whiz
347 posts since Feb 2008
Reputation Points: 27
Solved Threads: 1
 

If you have a long number of mails in your db, then it is better to use sleep function to avoid overload of server....
Read more about this on gooogle.....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

the sleep function pauses the mysql statement. i cannot see how that would solve the problem of my array not being populated.

kevin wood
Posting Whiz
347 posts since Feb 2008
Reputation Points: 27
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You