Need help formatting query for mail()

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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_mailinglist, $mailinglist);
    $query_email = "SELECT * FROM emailaddress";
    $email = mysql_query($query_email, $mailinglist) or die(mysql_error());
    $row_email = mysql_fetch_assoc($email);
    $totalRows_email = mysql_num_rows($email);

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


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

    Joe Guest

  2. Similar Questions and Discussions

    1. Need help formatting syntax for SELECT query on a Bittype data field
      :confused; I have been trying to build a SQL statement in my coldfusion page that queries our SQL Server database for a bunch of records. I want to...
    2. CDO mail formatting issue
      Hi, When I set the following for my CDO email, the mail is receievd with the html portion does not appear formatted but just as it is seen below. I...
    3. Mail formatting problem
      I'm using this code below. It sends the emails ok but none ofthe body isformatted. Any ideas? Thanks Andy <% Dim BodyString
    4. <cfoutput query> and TABLE formatting
      HI, I'm trying to output images from a database using <cfoutput query>. That part works fine. But the images display all in one column, one...
    5. E-mail formatting?
      When e-mailing invoices and estimates, is there any way to customize the presentation of the e-mail beyond changing the message? Specifically, I'd...
  3. #2

    Default Re: Need help formatting query for mail()

    Joe wrote:
    > mysql_select_db($database_mailinglist, $mailinglist);
    > $query_email = "SELECT * FROM emailaddress";
    > $email = mysql_query($query_email, $mailinglist) or die(mysql_error());
    > $totalRows_email = mysql_num_rows($email);
    while($row_email = mysql_fetch_assoc($email)) {
    $to = $row_email['addresses']; // where addresses is your column name
    $subject = "Your subject";
    $message = "Your message";
    $headers = "From: [email]you@email.com[/email]\r\n";

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


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

    Sugapablo Guest

  4. #3

    Default Re: Need help formatting query for mail()

    Thank you Sugapablo!!!

    in article [email]vmn3j1i9dkbkfe@corp.supernews.com[/email], Sugapablo at
    [email]russREMOVE@sugapablo.com[/email] wrote on 9/19/03 6:12 PM:
    > Joe wrote:
    >> mysql_select_db($database_mailinglist, $mailinglist);
    >> $query_email = "SELECT * FROM emailaddress";
    >> $email = mysql_query($query_email, $mailinglist) or die(mysql_error());
    >> $totalRows_email = mysql_num_rows($email);
    >
    > while($row_email = mysql_fetch_assoc($email)) {
    > $to = $row_email['addresses']; // where addresses is your column name
    > $subject = "Your subject";
    > $message = "Your message";
    > $headers = "From: [email]you@email.com[/email]\r\n";
    >
    > mail($to, $subject, $message, $headers);
    > }
    >
    Joe Guest

  5. #4

    Default Re: Need help formatting query for mail()


    "Sugapablo" <russREMOVE@sugapablo.com> wrote in message
    news:vmn3j1i9dkbkfe@corp.supernews.com...
    > Joe wrote:
    > > mysql_select_db($database_mailinglist, $mailinglist);
    > > $query_email = "SELECT * FROM emailaddress";
    > > $email = mysql_query($query_email, $mailinglist) or die(mysql_error());
    > > $totalRows_email = mysql_num_rows($email);
    >
    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_email = mysql_fetch_assoc($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: [email]you@email.com[/email]\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.




    Richard Hockey Guest

  6. #5

    Default 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:
    >$subject = "Your subject";
    >$message = "Your message";
    >$headers = "From: [email]you@email.com[/email]\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.
    You can use bcc:

    $recipient = "My customers";
    $subject = "Your subject";
    $message = "Your message";
    $headers = "bcc: $to\nFrom: [email]you@email.com[/email]\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 [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  7. #6

    Default Re: Need help formatting query for mail()


    > mail($to, $subject, $message, $headers);
    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 [url]www.geog.cam.ac.uk/~mvl22[/url]
    [url]www.lucas-smith.co.uk[/url]


    Martin Lucas-Smith Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139