I'm trying to send a simple email to all users in my mySQL database. Here is what I currently have:
Code: Select all
error_reporting(E_ALL);
echo "Please be patient...";
$html = stripslashes($_POST["bpost"]);
$subj = stripslashes($_POST["subjectpost"]);
$address = $_POST['address'];
$fullname = $_POST['fullname'];
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
require_once "../lib/Swift/Plugin/Decorator.php";
include("../connection.php"); //database connection
if ($_POST['entire'] == "yes") {
$smtp =& new Swift_Connection_SMTP("smtp.host.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername("username");
$smtp->setpassword("password");
$swift =& new Swift($smtp);
$recipients =& new Swift_RecipientList();
$sql = "SELECT usrID, usrEmail as '[name]', usrFirst, UsrLast";
$sql .= " FROM tblUsers AS ";
$sql .= " WHERE usrActive = '1'";
$sql .= " ORDER BY usrEmail";
$result=mysql_db_query($DBname,$sql,$link);
while ($row=mysql_fetch_array($result)) {
$recipients->addTo($row['usrEmail']);
$bod = $html;
$bod .= "<br>Your email is address is: [name]";
$message =& new Swift_Message($subj, $bod, "text/html");
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
}
if ($swift->batchSend($message, $recipients, new Swift_Address($address, $fullname))) {
print" <script>
window.location=\"emailUsers.php?msg=1\"
</script> ";
}
else {
print ("<p>No go!</p>");
}
$swift->disconnect();
} //end IF
Any help is much appreciated!Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/kylerenk/public_html/pacificbb2/secure/swift.php on line 36
Notice: Undefined variable: message in /home/user/public_html/usr/secure/swift.php on line 48
Catchable fatal error: Argument 1 passed to Swift::batchSend() must be an instance of Swift_Message, null given, called in /home/user/public_html/usr/secure/swift.php on line 48 and defined in /home/user/public_html/usr/lib/Swift.php on line 484