Jump to content

Archived

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

xux

Can I get help on a Newsletter Script from Anybody Here?

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

Share this post


Link to post
Share on other sites
Did you copy this code from somewhere?  The comments are telling you exactly what to do...

[quote author=xux link=topic=109406.msg440873#msg440873 date=1159191071]
  //error suppressed,remove it to see what happens
  @$success=mail($toAddress,$subject,$message);
[/quote]

Remove the @ from the front of the line and see if it helps.

Regards
Huggie

Share this post


Link to post
Share on other sites
I'll bet you that the From: parm is required (some servers do).
4th string in [code=php:0]mail($toAddress,$subject,$message, "From: me@mysite.com");[/code]

ROnald  8)

Share this post


Link to post
Share on other sites
It was not copied from anywhere,I thought I had came up with a perfect code.It wasnt reporting any error but it just echoing "Newsletter cant be send".So it looks like a logical error.Thanks

Share this post


Link to post
Share on other sites
In addition to Ronald's comments, if you ever have problems with this sort of thing, try going back to basics and adding in additional bits as you go to see what happens.

Regards
Huggie

Share this post


Link to post
Share on other sites
Thanks,
          Let me implement those changes.I will keep you inform.Thanks

Share this post


Link to post
Share on other sites
Hi,
    After trying out the suggestion given to me,the script is still not working.It it a bit complicated because I want to send the newsletter in html format,it would have been easier in plain language but html is the required format.so please what help/suggestion are you going to give.Thanks

Share this post


Link to post
Share on other sites
change [color=red]$toAddress=$result;[/color]
to [color=blue]$toAddress=$row['email'];[/color]

Share this post


Link to post
Share on other sites
I've just broken the code down and tried the following to my hotmail.co.uk address and not only did it arrive ok, but it went into the inbox as opposed to the junk mail.

Try copying and pasting this code into a page and seeing if it works, just replace the toAddress.

[code]
<?php
  $message = "<h1>Test HTML email</h1><img src=\"http://www.dizzie.co.uk/myspace/sig.gif\" alt=\"Signature\">";

  // Set some parameters
  $toAddress = "myemailaddress@hotmail.co.uk";
  $subject = "Test Subject";
  $headers = "Content-type: text/html\n\n";

  // Try to send the message
  $success = mail($toAddress,$subject,$message,$headers);

  if($success){
      print "Newsletter Sent";
  }
  else{
      echo'Newwsletter could not be sent';
  } 
?>
[/code]

Assuming that this works ok then add bits to it gradually.

Regards
Huggie

Share this post


Link to post
Share on other sites
Hi,
    I tested your code and it work perfectly alright,but it was send to the junk of my yahoo.On getting to my junk,i actually found out that the code i posted(the one I felt was not working) have been sending
[code]header.tplfooter.tpl[/code]
to the my email(I was using it to test the code),so i think I hve isolated the problems which I hope you will be kind enough to help me solve
1.The code has not been grabbing the header(an image),the content and the footer (which is an image too)
2.It has been echoing "Newsletter can not be sent" while it have been sending it
Am sure you will be able to help me out on it.
Thanks a lot,I appreciate your help.
My Regards
Dayo

Share this post


Link to post
Share on other sites
Hi,
    I tested your code and it work perfectly alright,but it was send to the junk of my yahoo.On getting to my junk,i actually found out that the code i posted(the one I felt was not working) have been sending

[code]header.tplfooter.tpl[/code]

to the my email(I was using it to test the code),so i think I hve isolated the problems which I hope you will be kind enough to help me solve
1.The code has not been grabbing the header(an image),the content and the footer (which is an image too)
2.It has been echoing "Newsletter can not be sent" while it have been sending it
Am sure you will be able to help me out on it.
3.Sending the newsletter to the emails stored in the database
Thanks a lot,I appreciate your help.
My Regards
Dayo

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.