Page 1 of 1

Mass Email [RESOLVED]

Posted: Wed Jul 08, 2015 5:50 pm
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?

Re: Mass Email

Posted: Wed Jul 08, 2015 10:30 pm
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/>

Re: Mass Email

Posted: Thu Jul 09, 2015 11:13 am
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 :(

Re: Mass Email

Posted: Thu Jul 09, 2015 11:16 am
by KyleMassacre
I noticed there is no closing for m tag? </form>

Re: Mass Email

Posted: Thu Jul 09, 2015 11:23 am
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/>

Re: Mass Email

Posted: Thu Jul 09, 2015 11:41 am
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?

Re: Mass Email

Posted: Thu Jul 09, 2015 11:51 am
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`)

Re: Mass Email

Posted: Thu Jul 09, 2015 12:20 pm
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

Re: Mass Email

Posted: Thu Jul 09, 2015 12:23 pm
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

Re: Mass Email

Posted: Thu Jul 09, 2015 12:25 pm
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