I need to be able to set up an email facility for a website that
1. has a small number of templates (eg. header, editable main text body and footer, the information for which will be in a MySQL database)
2. can be sent to multiple email addresses (addresses taken from the same database but different table)
3. use different lists of addresses dependent upon subscription options
I've had varying success so far using PHPMailer v2 and v5
With v2 I was able to create an editable template page and preview page that allowed sending a test email to an address specified within the script. This sorted issue no. 1, however I was unable to get an array of email addresses working so nos 2 & 3 failed.
With v5, which actually announces that it works with databases for multiple email addresses, I'm yet to manage anything worth mentioning.
There's an example with the PHPMailer 5 download for just such a project, the main chunk of which is:
The result of using this (with all the real password, username etc bit in) is
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ... on line 22
Line 22 is "while ($row = mysql_fetch_array ($result))"
I really need to get this sorted, but am hitting a very large brick wall.
Any thoughts?
thanks
Steve
1. has a small number of templates (eg. header, editable main text body and footer, the information for which will be in a MySQL database)
2. can be sent to multiple email addresses (addresses taken from the same database but different table)
3. use different lists of addresses dependent upon subscription options
I've had varying success so far using PHPMailer v2 and v5
With v2 I was able to create an editable template page and preview page that allowed sending a test email to an address specified within the script. This sorted issue no. 1, however I was unable to get an array of email addresses working so nos 2 & 3 failed.
With v5, which actually announces that it works with databases for multiple email addresses, I'm yet to manage anything worth mentioning.
There's an example with the PHPMailer 5 download for just such a project, the main chunk of which is:
Code:
@mysql_connect('localhost', 'username', 'password');
@mysql_select_db("database_name");
$query = "SELECT * FROM subs WHERE exhibitions='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();
}
The result of using this (with all the real password, username etc bit in) is
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ... on line 22
Line 22 is "while ($row = mysql_fetch_array ($result))"
I really need to get this sorted, but am hitting a very large brick wall.
Any thoughts?
thanks
Steve