xux Posted September 25, 2006 Share Posted September 25, 2006 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 codeCode:<?php $message= "header.tpl".$contents."footer.tpl"; ?><?php// connecting to MySQL server$connection = mysql_pconnect('localhost', '', '') or die ('Unable to connect!');// selecting database for usemysql_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 returnedif (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 setmysql_free_result($result); ?> Please I will appreciate your help.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/ Share on other sites More sharing options...
HuggieBear Posted September 25, 2006 Share Posted September 25, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98143 Share on other sites More sharing options...
ronverdonk Posted September 25, 2006 Share Posted September 25, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98148 Share on other sites More sharing options...
xux Posted September 25, 2006 Author Share Posted September 25, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98151 Share on other sites More sharing options...
HuggieBear Posted September 25, 2006 Share Posted September 25, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98152 Share on other sites More sharing options...
xux Posted September 25, 2006 Author Share Posted September 25, 2006 Thanks, Let me implement those changes.I will keep you inform.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98191 Share on other sites More sharing options...
xux Posted September 25, 2006 Author Share Posted September 25, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98297 Share on other sites More sharing options...
alpine Posted September 25, 2006 Share Posted September 25, 2006 change [color=red]$toAddress=$result;[/color]to [color=blue]$toAddress=$row['email'];[/color] Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98313 Share on other sites More sharing options...
HuggieBear Posted September 25, 2006 Share Posted September 25, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98316 Share on other sites More sharing options...
xux Posted September 25, 2006 Author Share Posted September 25, 2006 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 solve1.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 itAm sure you will be able to help me out on it.Thanks a lot,I appreciate your help.My RegardsDayo Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98354 Share on other sites More sharing options...
xux Posted September 26, 2006 Author Share Posted September 26, 2006 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 solve1.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 itAm sure you will be able to help me out on it.3.Sending the newsletter to the emails stored in the databaseThanks a lot,I appreciate your help.My RegardsDayo Quote Link to comment https://forums.phpfreaks.com/topic/21974-can-i-get-help-on-a-newsletter-script-from-anybody-here/#findComment-98800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.