xux Posted September 21, 2006 Share Posted September 21, 2006 Hi, I am trying to set up a newsletter script but it is saying cannot send newsletter.Please I need urgent help.here is the code[code]<?php $message= "header.tpl".$contents."footer.tpl"; ?><?php// connecting to MySQL server$connection = mysql_pconnect('localhost', '', '') or die ('Unable to connect!');// selecting database for usemysql_select_db('db') or die ('Unable to select database!');// create and execute query$query = 'SELECT email FROM newsletter';$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());// check if records were returnedif (mysql_num_rows($result) > 0){while($row = mysql_fetch_array($result)) $toAddress=$result; $subject=$header."\n"; //error suppressed,remove it to see what happens @$success=mail($toAddress,$subject,$message);}if($success){print "Newsletter Sent"; }else{ echo'Newwsletter could not be sent'; } // once processing is complete// free result setmysql_free_result($result); ?> [/code]Please I will appreciate your help.Thanks Link to comment https://forums.phpfreaks.com/topic/21542-help-on-newsletter-script/ Share on other sites More sharing options...
printf Posted September 21, 2006 Share Posted September 21, 2006 $result is the resouce handle, so....[code]$toAddress=$result;[/code]needs to be...[code]$toAddress = $row['email'];[/code]But a better idea, is to never waste more memory by assigning a variable to another variable that already holds that value. For small scripts it does not pose a problem, but for larger script you will waste unneeded resources and over load the scope of your script doing that!instead of...[code] $toAddress=$result; $subject=$header."\n"; //error suppressed,remove it to see what happens @$success=mail($toAddress,$subject,$message);[/code]use...[code] @$success=mail($row['email'],$header,$message);[/code]me! Link to comment https://forums.phpfreaks.com/topic/21542-help-on-newsletter-script/#findComment-96134 Share on other sites More sharing options...
xux Posted September 21, 2006 Author Share Posted September 21, 2006 Hi, I have made those changes and it is still reporting Newsletter could not be sent. Link to comment https://forums.phpfreaks.com/topic/21542-help-on-newsletter-script/#findComment-96139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.