email address from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    email address from mysql

    Need help as a newbie I'm trying to create auto email everytime the users execute the button below. Please tell me what wrong with my mail.php file

    [PHP]
    <html>
    <head>


    <form action="mail.ph p" method="POST" enctype="multip art/form-data">

    <input type="submit" value="mail now">
    </p>
    </form>

    </body>
    </html>
    [/PHP]

    Here's the PHP email (mail.php) and I don't know how to do it, but I know that my sql is just working fine.

    [PHP]
    <?php

    # Connect to the database
    $dbLink = mysql_connect(" localhost", "xxx", "xxxxxxxx")
    or die("Error! Failed to connect to the MySQL server!");
    mysql_select_db ("cmr", $dbLink)
    or die("Error! Failed to select a database!");

    #query
    $query="
    SELECT m.email, f.approval1
    from filestorage f, members m
    where f.approved='N'
    and f.approval1=m.n ame


    $result = @MYSQL_QUERY($q uery);

    while ($row = mysql_fetch_arr ay ($result)) {
    // HTML body
    $body = "Hello <font size=\"4\">" . $row["full_name"] . "</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["approval1"] . ", \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($ro w["email"], $row["approval1"]);

    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->ClearAttachmen ts();
    }


    ?>
    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ddtpmyra.

    Where do you initialize $mail?

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #3
      I'm totally clueless, can you show me a simple email script that email address comes from mysql or any database?

      thanks!

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        You should be pretty close. You'll just need to add something like this:

        [code=php]
        $result = @MYSQL_QUERY($q uery);

        require_once 'class.phpmaile r.php';
        $mail = new PHPMailer();


        while ($row = mysql_fetch_arr ay ($result)) {
        [/code]

        The require_once() path might change depending on where you keep the PHPMailer class file.

        Comment

        Working...