Jump to content

Archived

This topic is now archived and is closed to further replies.

xux

Help on Newsletter Script

Recommended Posts

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 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);
           
?>
[/code]
Please I will appreciate your help.
Thanks

Share this post


Link to post
Share on other sites
$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!

Share this post


Link to post
Share on other sites
Hi,
  I have made those changes and it is still reporting Newsletter could not be sent.

Share this post


Link to post
Share on other sites

×

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.