PHP Array from SQL Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • border9
    New Member
    • Jan 2008
    • 10

    PHP Array from SQL Database

    What im attempting to do is pull email address from a database already built, i need to be able to select the email address depending on the date they are given.

    Then i need to be able to Implode the list of email address so i can send out multiple emails to multiple Clients at one time. This is what i have so far.


    *************** ***Form Application**** ************

    <select name="emailto" size="15" multiple id="emailto" style="color: #000000; font-size: 8pt; font-family: Verdana" tabindex="">

    <?php
    $users_sql = "SELECT * FROM ******* WHERE site_tag = '*****' AND date_received BETWEEN '" . $_POST["startDate"] . "' AND '" . $_POST["endDate"] . "'";
    $users_result = @mysql_query($u sers_sql);
    while($users = @mysql_fetch_ar ray($users_resu lt))

    {
    echo "<option";

    echo">" . $users["email"] ;
    echo",</option>\n";

    }

    ?>
    </select>

    *************** ***********
    *************** ***********php code*********** **********

    if($_POST['email_now'])
    {

    $to = $_POST['emailto'];
    $from = "************** *";
    $subject = "************** *****";
    $headers .= ''************* **".$eol;
    $headers .= '************** '.$eol;
    $headers .= 'Return-Path: '.$eol; // these two to set reply address
    $headers .= "Message-ID: <".$subject.">" .$eol;
    //$headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['SERVER_NAME'].">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters
    # Boundry for marking the split & Multitype Headers
    $mime_boundary= md5(time());
    $headers .= 'MIME-Version: 1.0'.$eol;
    $headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
    $body= $_POST['edited'];
    //EOF;

    $success = mail($to, $subject, $body, $headers);

    if ($success)
    {
    $msg="";
    mass_email($msg );


    }
    else
    {
    $msg=".";
    mass_email($msg );

    }
    }

    But what i need it to do is when i select or whoever i select from that form and click Email, it emails all of them. and i cant figure out for the life of me what im doing wrong.
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Could you please tell us,what is NOT working in this script?
    Please USE CODE tags in future.

    Comment

    • border9
      New Member
      • Jan 2008
      • 10

      #3
      Its not allowing me to send to the email address the Form brings up. Right now i have it pulling about 15 email addresses from the Database and its not sending to them only one.

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Print your emails in the list menu like this: set the name attribute in this way emailto[]

        [CODE=html]
        <select name="emailto[]" multiple="MULTI PLE" id="emailto[]">
        <option value="1@domain .com">1@domain. com</option>
        <option value="2@domain .com">2@domain. com</option>
        <option value="3@domain .com">3@domain. com</option>
        </select>[/CODE]

        On server page
        [CODE=php]<?php
        $toArray = $_POST['emailto'];
        $explodedString = implode(",",$to Array);
        echo $explodedString ;
        ?>[/CODE]


        Outputs:
        Code:
        1@domain.com,2@domain.com,3@domain.com
        Pass the $explodedString to the mail() function.

        Comment

        • border9
          New Member
          • Jan 2008
          • 10

          #5
          Originally posted by ajaxrand
          Print your emails in the list menu like this: set the name attribute in this way emailto[]

          [CODE=html]
          <select name="emailto[]" multiple="MULTI PLE" id="emailto[]">
          <option value="1@domain .com">1@domain. com</option>
          <option value="2@domain .com">2@domain. com</option>
          <option value="3@domain .com">3@domain. com</option>
          </select>[/CODE]

          On server page
          [CODE=php]<?php
          $toArray = $_POST['emailto'];
          $explodedString = implode(",",$to Array);
          echo $explodedString ;
          ?>[/CODE]


          Outputs:
          Code:
          1@domain.com,2@domain.com,3@domain.com
          Pass the $explodedString to the mail() function.
          I see where your going with that, But i need to pull the emails from the database, they arent emails i put in myself. That Form is built off email address from the mySQL Database. How do i create the array from the emails in the database?

          Comment

          • border9
            New Member
            • Jan 2008
            • 10

            #6
            Anyone have any idea what im trying to attempt here or what i have to do to make it work?

            If you can help please by all means i would greatly appricate it. Thanks

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Oh you want to build the List menu right?
              Sorry I don't have a Email Database with me, So I'm using one of my existing database.

              [code=php]
              <?php
              @mysql_connect( "localhost","ro ot","dba")or die(mysql_error ());
              @mysql_select_d b("my_store") or die(mysql_error ());
              $result = mysql_query("SE LECT p_name from products");
              while($row=mysq l_fetch_array($ result)){
              $options .= '<option value="'.$row['p_name'].'">'.$row['p_name'].'</option>';
              }
              ?>
              <html>
              <body>
              <form action="index.p hp" method="post">
              <select name="emailto[]" multiple="MULTI PLE" id="emailto[]">
              <?php echo $options ?>
              </select>
              <input type="submit" name="Submit" value="Submit" />
              </form>
              </body>
              </html>
              [/code]

              Comment

              • border9
                New Member
                • Jan 2008
                • 10

                #8
                Ok, so that builds the menu, how do i take whats in that menu and email all of the clients that are brought up in that menu?

                I need to be able to Click iether 1 or 20 of those items in that menu and be able to email the. Any ideas?

                Comment

                • border9
                  New Member
                  • Jan 2008
                  • 10

                  #9
                  [PHP]
                  <?php
                  if($_POST['email_now'])
                  {

                  $to = $_POST['emailto'];
                  $from = "";
                  $subject = "";
                  $headers .= "".$eol;
                  $headers .= "".$eol;
                  $headers .= 'Return-Path: '.$eol; // these two to set reply address
                  $headers .= "Message-ID: <".$subject.">" .$eol;
                  //$headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['SERVER_NAME'].">".$eol;
                  $headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters
                  # Boundry for marking the split & Multitype Headers
                  $mime_boundary= md5(time());
                  $headers .= 'MIME-Version: 1.0'.$eol;
                  $headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
                  $body= $_POST['edited'];
                  //EOF;

                  $success = mail($to, $subject, $body, $headers);

                  if ($success)
                  {
                  $msg="";
                  mass_email($msg );


                  }
                  else
                  {
                  $msg=".";
                  mass_email($msg );

                  }
                  }
                  ?>
                  [/PHP]

                  I need this code to be able to read iether 1 or multiple selections for the List that is created from the database. What i need it to do is Send out an Email to any Selected Items from that list.

                  Comment

                  • border9
                    New Member
                    • Jan 2008
                    • 10

                    #10
                    Can anyone see what im trying to acomplish here?

                    Comment

                    • ak1dnar
                      Recognized Expert Top Contributor
                      • Jan 2007
                      • 1584

                      #11
                      Originally posted by border9
                      Ok, so that builds the menu, how do i take whats in that menu and email all of the clients that are brought up in that menu?

                      I need to be able to Click iether 1 or 20 of those items in that menu and be able to email the. Any ideas?
                      The code snippet that I've posted here will build the list menu. Then What you have to do, Select the recipient from that List (You can select 1 or more email addresses ) and submit those addresses to the php script which sends the mail. If you want to send the mail with out any user interaction WHY you need this LIST MENU, just pass the emails to the mail() function.

                      Comment

                      • border9
                        New Member
                        • Jan 2008
                        • 10

                        #12
                        Originally posted by ajaxrand
                        The code snippet that I've posted here will build the list menu. Then What you have to do, Select the recipient from that List (You can select 1 or more email addresses ) and submit those addresses to the php script which sends the mail. If you want to send the mail with out any user interaction WHY you need this LIST MENU, just pass the emails to the mail() function.
                        Mainly i want the USER to be able to Select AS many AS theyd like to email one email to. OR if they would like to email them all. Im trying to get the code you gave me working right know, ill let you know if that was what i was looking for. Thank you.

                        Comment

                        • border9
                          New Member
                          • Jan 2008
                          • 10

                          #13
                          Ok, it seems to be kind of working, my next question would be how do i strip out duplicate email address? thanks

                          Comment

                          • border9
                            New Member
                            • Jan 2008
                            • 10

                            #14
                            [PHP]emailto[][/PHP]

                            Im confused how do i make the php Email call this command?

                            [PHP]if($_POST['email_now'])
                            {

                            $to = emailto[];
                            $from = "";
                            $subject = "" .$quote;
                            $headers .= ''.$eol;
                            $headers .= ''.$eol;
                            $headers .= ''.$eol;
                            $headers .= "Message-ID: <".$subject.">" .$eol;
                            $headers .= "X-Mailer: PHP v".phpversion() .$eol;
                            $mime_boundary= md5(time());
                            $headers .= 'MIME-Version: 1.0'.$eol;
                            $headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
                            $body= $_POST['edited'];
                            //EOF;
                            $success = mail($to, $subject, $body, $headers);

                            if ($success)
                            {
                            $msg="";
                            mass_email($msg );


                            }
                            else
                            {
                            $msg="";
                            mass_email($msg );

                            }
                            }[/PHP]
                            I dont follow how i make this code call the List that you made it produce?

                            Comment

                            Working...