Need help formatting query for mail()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    Need help formatting query for mail()

    I want to use mail() to send a message to a group of addresses in a mysql
    table. I¹ve got my mail script and my sql query, but I don¹t know how to
    format the query results to fit into the mail() function.

    Does anyone have a simple script that will format a list of email addresses
    (from a mysql query) then dump them into a variable that I can use in a
    mail() function?

    Here¹s what I got so far:

    mysql_select_db ($database_mail inglist, $mailinglist);
    $query_email = "SELECT * FROM emailaddress";
    $email = mysql_query($qu ery_email, $mailinglist) or die(mysql_error ());
    $row_email = mysql_fetch_ass oc($email);
    $totalRows_emai l = mysql_num_rows( $email);

    mail($addresses , "Successful Test", "Successful mail sent")


    FYI ... I¹m a novice programmer at best ...

  • Sugapablo

    #2
    Re: Need help formatting query for mail()

    Joe wrote:[color=blue]
    > mysql_select_db ($database_mail inglist, $mailinglist);
    > $query_email = "SELECT * FROM emailaddress";
    > $email = mysql_query($qu ery_email, $mailinglist) or die(mysql_error ());
    > $totalRows_emai l = mysql_num_rows( $email);[/color]

    while($row_emai l = mysql_fetch_ass oc($email)) {
    $to = $row_email['addresses']; // where addresses is your column name
    $subject = "Your subject";
    $message = "Your message";
    $headers = "From: you@email.com\r\n";

    mail($to, $subject, $message, $headers);
    }


    --
    Sugapablo
    ------------------------------------
    http://www.sugapablo.com <--music
    http://www.sugapablo.net <--personal

    Comment

    • Joe

      #3
      Re: Need help formatting query for mail()

      Thank you Sugapablo!!!

      in article vmn3j1i9dkbkfe@ corp.supernews. com, Sugapablo at
      russREMOVE@suga pablo.com wrote on 9/19/03 6:12 PM:
      [color=blue]
      > Joe wrote:[color=green]
      >> mysql_select_db ($database_mail inglist, $mailinglist);
      >> $query_email = "SELECT * FROM emailaddress";
      >> $email = mysql_query($qu ery_email, $mailinglist) or die(mysql_error ());
      >> $totalRows_emai l = mysql_num_rows( $email);[/color]
      >
      > while($row_emai l = mysql_fetch_ass oc($email)) {
      > $to = $row_email['addresses']; // where addresses is your column name
      > $subject = "Your subject";
      > $message = "Your message";
      > $headers = "From: you@email.com\r\n";
      >
      > mail($to, $subject, $message, $headers);
      > }
      >[/color]

      Comment

      • Richard Hockey

        #4
        Re: Need help formatting query for mail()


        "Sugapablo" <russREMOVE@sug apablo.com> wrote in message
        news:vmn3j1i9dk bkfe@corp.super news.com...[color=blue]
        > Joe wrote:[color=green]
        > > mysql_select_db ($database_mail inglist, $mailinglist);
        > > $query_email = "SELECT * FROM emailaddress";
        > > $email = mysql_query($qu ery_email, $mailinglist) or die(mysql_error ());
        > > $totalRows_emai l = mysql_num_rows( $email);[/color]
        >[/color]

        You can send to multiple recipients with one call to the function mail(), if
        you place the e-mail addresses in a comma seperatd list

        $to="";

        // loop through database query to fetch recipient e-mail addresses
        // output comma seperated list of e-mail addresses in $to
        while($row_emai l = mysql_fetch_ass oc($email))
        {
        if($to!="") $tp.=", ";
        $to.= $row_email['addresses']; // where addresses is your column name
        }

        // assuming the message subject and content are the same for all the
        messages
        $subject = "Your subject";
        $message = "Your message";
        $headers = "From: you@email.com\r\n";
        mail($to, $subject, $message, $headers);

        There is one disadvantage to this, in that the message header the recipients
        see will contain a list of all the e-mail addresses the message was sent to.




        Comment

        • Geoff Berrow

          #5
          Re: Need help formatting query for mail()

          I noticed that Message-ID: <3f6d6933$0$254 $cc9e4d1f@news. dial.pipex.com>
          from Richard Hockey contained the following:
          [color=blue]
          >$subject = "Your subject";
          >$message = "Your message";
          >$headers = "From: you@email.com\r\n";
          > mail($to, $subject, $message, $headers);
          >
          >There is one disadvantage to this, in that the message header the recipients
          >see will contain a list of all the e-mail addresses the message was sent to.[/color]

          You can use bcc:

          $recipient = "My customers";
          $subject = "Your subject";
          $message = "Your message";
          $headers = "bcc: $to\nFrom: you@email.com\r\n";
          mail($to, $subject, $message, $headers);

          --
          Geoff Berrow
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • Martin Lucas-Smith

            #6
            Re: Need help formatting query for mail()


            [color=blue]
            > mail($to, $subject, $message, $headers);[/color]

            A useful technique is to change this to

            mail($to, $subject, wordwrap ($message), $headers);

            so that the message line length is kept to <80 characters, for
            compatibility with most/all mail clients.



            Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22



            Comment

            Working...