+ Reply to Thread
Results 1 to 5 of 5

Thread: database driven html email problem

  1. #1
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    database driven html email problem

    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:

    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

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: database driven html email problem

    put this code in before the line that generates the error so we can get some more information:

    Code:
    if (!$result) {
         exit(mysql_error());
    }
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Re: database driven html email problem

    Thanks, that was a huge help, showed I'd messed up with the wrong username
    - been flipping between the test and live sites where there's a couple of differences due to hosting set up

    big oops!

    Now I just have to work out the SMTP error messages, I'm guessing to do with authentication, so no doubt I'll be posting another problem soon!

    thanks again

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: database driven html email problem

    No problem

    If you have any more issues, let me know.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: database driven html email problem

    Just for information, I have a multiple e-mailshot function on my CRM site.

    If you like it, I can forward you the scripts if you're interested.

    Mine too has a preview function for either plain text or html e-mail.

    The final page is a dynamic table of e-mails, with an option to check/uncheck those you want/ do not want to send to.

    I've also built in merge fields to pick up personal information of each recipient within the mailer.

    It also confirms each mail as it sends.
    Last edited by freecrm; 06-03-2009 at 11:07 AM.

+ Reply to Thread

Similar Threads

  1. email problem.
    By DotMoth in forum Free Hosting
    Replies: 2
    Last Post: 11-29-2008, 11:29 AM
  2. problem database
    By Eugene Na in forum Free Hosting
    Replies: 1
    Last Post: 12-11-2007, 07:03 AM
  3. Wordpress Database Password Problem
    By roropheno in forum Free Hosting
    Replies: 8
    Last Post: 12-08-2007, 03:11 AM
  4. Email Problem
    By lunamaya in forum Feedback and Suggestions
    Replies: 5
    Last Post: 10-18-2007, 01:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers