kev wood Posted March 6, 2009 Share Posted March 6, 2009 i am trying to write some code that will send an email to user's who are registered on a site i am building. up to now it is not working. here is my code up to now. $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("Query failed : " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { $contactemail= "$row[address], "; } // Contacts //$replyName = $merc_replyId; //$replyEmail = $merc_replyAddress; $replyName = "PiPonliine"; $replyEmail = "[email protected]"; $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($contactemail, $subject, $message, $headers); echo "<h2>Email notification sent</h2>"; echo "<h2>1 record added</h2>"; any help would be much appreciated. Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/ Share on other sites More sharing options...
trq Posted March 6, 2009 Share Posted March 6, 2009 What is the problem? Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778021 Share on other sites More sharing options...
trq Posted March 6, 2009 Share Posted March 6, 2009 Actually, even without a descent description I can see the problem. This line.... $contactemail= "$row[address], "; should be.... $contactemail[] = $row['address']; Then, this line.... mail($contactemail, $subject, $message, $headers); should be.... mail(implode(',', $contactemail), $subject, $message, $headers); Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778023 Share on other sites More sharing options...
kev wood Posted March 6, 2009 Author Share Posted March 6, 2009 sorry for not stating the problem i have a bad headache today an am not functioning properly. the emails where not being sent. i will try your fix and get back to you. Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778024 Share on other sites More sharing options...
kev wood Posted March 6, 2009 Author Share Posted March 6, 2009 i am getting this error now Warning: implode(): Bad arguments. in /home/acmeart/public_html/pip/website3/cms/insert.php on line 122 Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778027 Share on other sites More sharing options...
kev wood Posted March 6, 2009 Author Share Posted March 6, 2009 i no the problem is with the array as it is not gettin populate i have tried a few different variants now an still get the same resulting error. here is what the array looks like now. $query = "SELECT email FROM emails"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); while($row = mysql_fetch_array($result)){ $contactemail = $row['email']. ", "; } Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778053 Share on other sites More sharing options...
kev wood Posted March 6, 2009 Author Share Posted March 6, 2009 i have got it sending out one email now so i no all the code is working except for this part $query = "SELECT email FROM emails"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $contactemail = $row[0]. ", "; } the results are not being stored in the array only one email address is stored. i have set the db up with three test email address so it should have more than one. Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778093 Share on other sites More sharing options...
trq Posted March 6, 2009 Share Posted March 6, 2009 the results are not being stored in the array only one email address is stored. Your not using any array. Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-778562 Share on other sites More sharing options...
kev wood Posted March 9, 2009 Author Share Posted March 9, 2009 got the code to work using the following code $query = "SELECT * FROM emails"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $contactemail = $row['email']; // Contacts //$replyName = $merc_replyId; //$replyEmail = $merc_replyAddress; $replyName = "PiPonliine"; $replyEmail = "[email protected]"; $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.">" . PHP_EOL; $headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL; mail($contactemail, $subject, $message, $headers); } echo "$contactemail"; echo "<h2>Email notification sent</h2>"; echo "<h2>1 record added</h2>"; mysql_close($con); Link to comment https://forums.phpfreaks.com/topic/148215-solved-send-email-on-mysql-db-update/#findComment-780282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.