entity Posted July 10, 2006 Share Posted July 10, 2006 Hey! I've recently decided to make my site a newsletter because it just seems cool. Anyway I've encountered a small problem.Well I've have people register an e-mail under a choosen user to be more specific about things. But when I go to send an e-mail it gives the username of the very first user, not the user specific to that e-mail and user combination. I'm using a str_replace() function so that when it finds {username} or {email} it will replace those with that users email and username in both the subject and message. Like so$message = str_replace("{username}", "$user", "$message");$message = str_replace("{email}", $email", "$message");And the same for $subject just replace $message with $subject ;)Now I've tried a few things, the last one was to reset those variablesmail(//all the mail stuff here ^_^);$user ="";$email = "";(this is all in a while loop, mind you!)but still it uses the very first user that the e-mails are allowed to be sent to! (Where recieve = 1 ;))Now this is the code used to send the newsletter.[code=php:0]$do = $_GET['version'];if((isset($do))&&($do=="do")) {$message = $_POST['message'];$subject = $_POST['subject'];$from = $_POST['from'];// Write News Letter to database$sql="INSERT INTO past_newsletters(content,subject,written) VALUES('$message','$subject',NOW())";if(!mysqli_query($con,$sql)){ die('Error: ' . mysqli_error());}$result99 = mysqli_query($con, "SELECT user, email FROM newsletter WHERE recieve='1' AND black='0'");$count = 0;while ($row99 = mysqli_fetch_array($result99)) {$user = $row99['user'];$email = $row99['email'];$message = str_replace("{username}", $user, $message);$message = str_replace("{email}", $email, $message);$message = stripslashes($message);$subject = str_replace("{username}", $user, $subject);$subject = str_replace("{email}", $email, $subject);$subject = stripslashes($subject);mail("$email", "$subject", "$message", "From: Entitys Arena <$from>");$email = "";$user = "";$count = $count + 1;}echo "Emails sent sucessfully.<br />Sent to: <b>$count</b> users.";}[/code]If there is [b]anyone[/b] who can help with this I will be majorly greatful!Thanks in advance!Entity ;) Quote Link to comment https://forums.phpfreaks.com/topic/14187-newsletter-script/ Share on other sites More sharing options...
willfitch Posted July 10, 2006 Share Posted July 10, 2006 That's odd.Using the test script:[code=php:0]<?php$username = 'Will';$string = 'Please help {name}.';$string = str_replace("{name}",$username,$string);echo $string;?>[/code]Works fine for me. It sounds like there is either an issue with the POSTed values, incorrect comparison (i.e. mistakenly entering {name} rather than {username}, or the rows being pulled back. Do a var_dump($_POST['message']) and tell me what it says. Quote Link to comment https://forums.phpfreaks.com/topic/14187-newsletter-script/#findComment-55608 Share on other sites More sharing options...
entity Posted July 10, 2006 Author Share Posted July 10, 2006 Done it now, thanks for the help! Was helpful as heck! Quote Link to comment https://forums.phpfreaks.com/topic/14187-newsletter-script/#findComment-55760 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.