PHPMailer / MySQL Array Problem

stevet70

New Member
Messages
35
Reaction score
0
Points
0
Attempting to get an example file for PHPMailer 5 to work, one that pulls info from a database to send to multiple recipients.

I've ammended the test file to include all my relevant settings (username, password, etc) but am getting the following error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

The full code I'm using (passwords etc changed of course) is this:

Code:
<?php

require("class.phpmailer.php");

$mail = new phpmailer();

$mail->From     = "list@example.com";
$mail->FromName = "List manager";
$mail->Host     = "mail.mydomain.com";
$mail->Mailer   = "smtp";

@mysql_connect('localhost', 'user', 'password');
@mysql_select_db("database_name");
$query  = "SELECT * FROM subs WHERE events='yes'";
$result = @mysql_query($query);

while($row = mysql_fetch_array($result))
{
    // HTML body
    $body  = "Hello <font size=\"4\">" . $row["first"] . "</font>, <p>";
    $body .= "<i>Your</i> personal photograph to this message.<p>";
    $body .= "Sincerely, <br>";
    $body .= "phpmailer List manager";

    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["first"] . ", \n\n";
    $text_body .= "Your personal photograph to this message.\n\n";
    $text_body .= "Sincerely, \n";
    $text_body .= "phpmailer List manager";

    $mail->Body    = $body;
    $mail->AltBody = $text_body;
    $mail->AddAddress($row["email"], $row["first"]);

    if(!$mail->Send())
        echo "There has been a mail error sending to " . $row["email"] . "<br>";

    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}

?>

Anything obvious shouting out?

There is a database table set up with the relevant columns and some results.

Ultimately I need to be able to send html emails with some content pulled from a database table (there will be several templates with editable text areas) as well as email addresses from another table based upon subscription options.

If anyone knows of a good tutorial covering that, written for beginners!, that would be useful too

many thanks
Steve
 
Top