Jump to content


Photo

Newsletter Script


  • Please log in to reply
2 replies to this topic

#1 entity

entity
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationEngland, UK

Posted 10 July 2006 - 03:27 PM

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 variables

mail(//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.

$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.";
}

If there is anyone who can help with this I will be majorly greatful!

Thanks in advance!

Entity ;)

#2 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 10 July 2006 - 03:44 PM

That's odd.

Using the test script:
<?php
$username = 'Will';
$string = 'Please help {name}.';
$string = str_replace("{name}",$username,$string);
echo $string;
?>

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.
Zend Certified Engineer (ZEND001989)
www.willfitch.com

#3 entity

entity
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationEngland, UK

Posted 10 July 2006 - 07:44 PM

Done it now, thanks for the help! Was helpful as heck!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users