Mass Email [RESOLVED]

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Mass Email [RESOLVED]

Post by Epiales »

Okay, another question. I have my code to inbox individual members in the game:

Code: Select all

<?php

if(isset($_POST['submit'])) {


$randid = rand(999,9999999);
$sql = "INSERT INTO messages (pid, subject, message, randid, date, sender) VALUES('$_POST[username]','$_POST[subject]', '$_POST[message]', '$randid', now(), 'System Message')";
$query = mysqli_query($db_lqls, $sql);

echo "<br><center><form method='post' action='admin_mass_email.php'><input type='submit' value='Back To Email'>"; 
    
    exit;
}
?>

<br />

<form name="email" action="admin_mass_email.php" method="post">

     Username
<br />
     <input name="username" type="text" size="50" id="username"><br /><br />
     Subject
<br />
     <input name="subject" type="text" size="50" id="subject"><br /><br />
     Message
<br />
     <textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
     <input type="submit" name="submit" value="Email!">

<br/><br/>
How can I write it so that I can inbox every user at the same time?
Last edited by Epiales on Thu Jul 09, 2015 1:08 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Mass Email

Post by KyleMassacre »

Code: Select all

<?php

if(isset($_POST['submit'])) {

$q = "select username from users";
$s = mysqli_query($db_lqls,$s);
while ($r = mysqlI_fetch_array($q,_MYSQLI_ASSOC)){
    $randid = rand(999,9999999);
    $sql = "INSERT INTO messages (pid, subject, message, randid, date, sender)VALUES('{$r['username']}','{$_POST['subject']}',  {$_POST['message']}', '$randid', now(), 'System Message')";
    $query = mysqli_query($db_lqls, $sql);
}
echo "<br><center><form method='post' action='admin_mass_email.php'><input type='submit' value='Back To Email'>"; 
    
    exit;
}
?>

<br />

<form name="email" action="admin_mass_email.php" method="post">
     Subject
<br />
     <input name="subject" type="text" size="50" id="subject"><br /><br />
     Message
<br />
     <textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
     <input type="submit" name="submit" value="Email!">

<br/><br/>
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Mass Email

Post by Epiales »

Okay, tried this based on what you put:

Code: Select all

<?php
if(isset($_POST['submit'])) {

$q = "select username from users";
$s = mysqli_query($db_lqls,$q);
while ($r = mysqli_fetch_array($s)){
    $randid = rand(999,9999999);
    $sql = "INSERT INTO messages (pid, subject, message, randid, date, sender)VALUES('{$r['username']}','{$_POST['subject']}',  {$_POST['message']}', '$randid', now(), 'System Message')";
    $query = mysqli_query($db_lqls, $sql);
}
echo "<br><center><form method='post' action='admin_mass_email.php'><input type='submit' value='Back To Email'>"; 
    
    exit;
}
?>

<br />

<form name="email" action="admin_mass_email.php" method="post">
     Subject
<br />
     <input name="subject" type="text" size="50" id="subject"><br /><br />
     Message
<br />
     <textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
     <input type="submit" name="submit" value="Email!">

<br/><br/>
And it doesn't input anything. It acts like it works, but no input of information :(
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Mass Email

Post by KyleMassacre »

I noticed there is no closing for m tag? </form>
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Mass Email

Post by Epiales »

KyleMassacre wrote:I noticed there is no closing for m tag? </form>
Yeah, </form> is on there as well now. Just goes to the "go back to email" link but inserts nothing

Code: Select all

 <?php

if(isset($_POST['submit1'])) {

$q = "select username from users";
$s = mysqli_query($db_lqls,$q);
while ($r = mysqli_fetch_array($s, MYSQLI_ASSOC)){
    $randid = rand(999,9999999);
    $sql = "INSERT INTO messages (pid, subject, message, randid, date, sender)VALUES('{$r['username']}','{$_POST['subject']}',  {$_POST['message']}', '$randid', now(), 'System Message')";
    $query = mysqli_query($db_lqls, $sql);
}
echo "<br><center><form method='post' action='admin_mass_email.php'><input type='submit' value='Back To Email'>"; 
    
    exit;
}
?>

<br />

<form name="email" action="admin_mass_email.php" method="post">
     Subject
<br />
     <input name="subject" type="text" size="50" id="subject"><br /><br />
     Message
<br />
     <textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
    <input type="submit" name="submit1" value="Email!"></form>

<br/><br/>
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Mass Email

Post by KyleMassacre »

It's probably something real stupid too. Can you show your table? Is pid supposed to be their username or their player ID?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Mass Email

Post by Epiales »

KyleMassacre wrote:It's probably something real stupid too. Can you show your table? Is pid supposed to be their username or their player ID?
`messid` int(11) NOT NULL AUTO_INCREMENT,
`pid` varchar(21) NOT NULL,
`subject` text NOT NULL,
`message` text NOT NULL,
`randid` int(8) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`sender` varchar(21) NOT NULL,
`readm` tinyint(1) NOT NULL DEFAULT '1',
`saved` enum('yes','no') NOT NULL DEFAULT 'no',
PRIMARY KEY (`messid`)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Mass Email

Post by KyleMassacre »

Do you have errors? You can check if mysqli_query() returns anything and if not you can see if there is a mysqli_error() and print it to the screen. Or print out the $sql variable and see if anything looks strange. Maybe some of the values are returning null so it won't insert since you have not null defined in the table structure for your columns
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Mass Email

Post by Epiales »

If I try to echo the $r['username'], which is where you have the username coming from the users table, I get all the names listed
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Mass Email

Post by KyleMassacre »

You would need to print it using print_r, var_dunp, or var_export. But I'm more interested in the $sql variable myself
Post Reply

Return to “Advanced Help and Support”