Jump to content

Help on Newsletter Script


xux

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.