Jump to content


Photo

Help on Newsletter Script


  • Please log in to reply
2 replies to this topic

#1 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 21 September 2006 - 03:18 PM

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
<?php
   
   $message= "header.tpl".$contents."footer.tpl";
   ?>
<?php
// connecting to MySQL server
$connection = mysql_pconnect('localhost', '', '') 
or die ('Unable to connect!');
// selecting database for use
mysql_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 returned
if (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 set
mysql_free_result($result);
             
?> 
Please I will appreciate your help.
Thanks

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 21 September 2006 - 03:47 PM

$result is the resouce handle, so....

$toAddress=$result;


needs to be...

$toAddress = $row['email'];

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

   $toAddress=$result;
   $subject=$header."\n";
   //error suppressed,remove it to see what happens
   @$success=mail($toAddress,$subject,$message);


use...

   @$success=mail($row['email'],$header,$message);




me!

#3 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 21 September 2006 - 04:07 PM

Hi,
  I have made those changes and it is still reporting Newsletter could not be sent.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users