Jump to content


Photo

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


  • Please log in to reply
10 replies to this topic

#1 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 September 2006 - 01:31 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

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 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 01:37 PM

Did you copy this code from somewhere?  The comments are telling you exactly what to do...

  //error suppressed,remove it to see what happens
  @$success=mail($toAddress,$subject,$message);


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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 25 September 2006 - 01:45 PM

I'll bet you that the From: parm is required (some servers do).
4th string in
mail($toAddress,$subject,$message, "From: me@mysite.com");

ROnald  8)
RTFM is an almost extinct art form, it should be subsidized.

#4 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 September 2006 - 01:51 PM

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

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 01:51 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 September 2006 - 02:22 PM

Thanks,
          Let me implement those changes.I will keep you inform.Thanks

#7 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 September 2006 - 04:17 PM

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

#8 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 25 September 2006 - 04:31 PM

change $toAddress=$result;
to $toAddress=$row['email'];

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 04:35 PM

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.

<?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';
   }   
?>

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 September 2006 - 05:09 PM

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
header.tplfooter.tpl
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



#11 xux

xux
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 26 September 2006 - 09:54 AM

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

header.tplfooter.tpl

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users