bravo14 Posted August 23, 2008 Share Posted August 23, 2008 Hi all I have written a piece of code that will send a newsletter to a set of email addresses in a table I also wanted to insert the newsletter into a separate table <?php include "connect.php"; if(isset($_POST['submit'])) { $subject=$_POST['subject']; $nletter=$_POST['nletter']; if(strlen($subject)<1) { print "You did not enter a subject."; } else if(strlen($nletter)<1) { print "You did not enter a message."; } else { $nletter=$_POST['nletter']; $subject=$_POST['subject']; $nletter=stripslashes($nletter); $subject=stripslashes($subject); $lists=$_POST['lists']; $nletter=str_replace("rn","<br>",$nletter); $adminmail="news@yardleyheroes.co.uk"; $path="http://www.yardleyheroes.co.uk/newsletter"; //the block above formats the letter so it will send correctly. $getlist='SELECT * FROM `email_table` WHERE `validated` = \'1\''; //select validated e-mails $getlist2=mysql_query($getlist) or die("Could not get list"); while($getlist3=mysql_fetch_array($getlist2)) { $headers = "From: $adminmail \r\n"; $headers.= "Content-Type: text/html; charset=ISO-8859-1 "; //send HTML enabled mail $headers .= "MIME-Version: 1.0 "; mail("$getlist3[email]","$subject","$nletter",$headers); } print "Newsletter Sent."; } } else { print "<form action='sendletter.php' method='post'>"; print "Subject:<br>"; print "<input type='text' name='subject' size='20' class='textbox'><br>"; print "Message:<br>"; include_once "includes/fckeditor/fckeditor.php"; $oFCKeditor = new FCKeditor('nletter'); $oFCKeditor->BasePath = "includes/fckeditor/"; $oFCKeditor->Value = ""; $oFCKeditor->Width = 540; $oFCKeditor->Height = 400; echo $oFCKeditor->CreateHtml(); print "<br><input type='submit' name='submit' value='submit' class='textbox'></form>"; } ?> The newsletter is sent ok, but the data is not added to the table, can anyone point out what I have done wrong? Cheers Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 Hmm where is your insert query? I should be something like this: <?php while($getlist3=mysql_fetch_array($getlist2)){ //send email $results = mysql_query("INSERT INTO newsletters (title, content) VALUES ('my newsletter', 'some content')") or die(); } ?> Or you can place it outside of the while() loop if you want to add just a single newsletter. Is this what you wanted? Quote Link to comment 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.