Please Help: Mass eMail [mySQL] needed.

GavinGavin BeginnerLink Clerk
Dear Coder(s).

Hi There, I am currently developing a Membership System to give me some more insights into the PHP and mySQL language. Please can a coder(s) help me do what I need to do, detail in Red Text.

What I have so far:
Member Register Form (Complete)
Member Login Form (Complete)
Member Change eMail Address / Profile / Password Form(s) (Complete)
Member Logout (Complete)
Admin Login (Complete)
Admin See Registered Users (Complete)
Admin Change Member Details - eMail Address / Password (Complete)
Admin Logout (Complete)

What I need help to do:
Admin Mass eMail Members (getting email address from mySQL table)

Above in Red is what i need help to do.

Many Thanks,
Best Regards, Gavin.

Comments

  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    1. How many recipients per email - estimates?
    2. Is it OK to lump the users together in a cc or bcc list? Or do you require 1 email per recipient?

    Why not just get some free mailing list scripts from one of the script sites?
  • GavinGavin Beginner Link Clerk
    I would like a php page with 2 fields
    1) Subject
    2) Message

    then when i press 'Submit' it connects to mySQL DB, retrieves the email address(s) then emails the members.

    .Gavin
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    That doesn't answer my question...

    My question is regarding how you want the email to be sent out:
    1. One email per recipient or
    2. Multiple recipients in a single email. If this method is OK, and you do not want the recipients to be aware of the other recipients, bcc can be used.
  • GavinGavin Beginner Link Clerk
    one email per recipient
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    Try this out (usual caveat - since I do not have a server with PHP installed, I have coded blindly without testing it out - some bugs may exist):

    In your html form, use:
    <form action="mailapp.php" method="post>
    name the content field as "message"
    name the subject field as "subject"

    Assumptions:
    1. Database Type = MySQL
    2. Database Host = "MyHost"
    3. Database Name = "MyDB"
    4. Database User = "MyUsr"
    5. Database User Password = "MyPwd"
    6. Table containing email addresses = "TBL_EMAIL"
    7. TBL_EMAIL only contains 1 field = "COL_ADDRESS"

    In your mailapp.php, enter the following:
    <?
    @mysql_connect("MyHost", "MyUsr", "MyPwd") or die("Cannot connect to MySQL");
    @mysql_select_db("MyDB") or die("Cannot select MyDB");
    
    $sql="SELECT * FROM TBL_EMAIL";
    $result=mysql_query($sql);
    
    if (mysql_numrows($result) == 0) :
        print "No email recipients to send to!";
    else :
        $cnt=0;
        while ($cnt < mysql_numrows($result)) :
            $address=mysql_result($result, $cnt, 'COL_ADDRESS');
            mail($address, $subject, $message, "From: Your_email_address");
            $cnt++;
        endwhile;
    endif;
    
    mysql_close();
    ?>
    
  • GavinGavin Beginner Link Clerk
    the script works but is this html code below right as this part isnt working,

    <html>
    <body>
    <form name="subject" method="post" action="">
    <input type="text" name="textfield">
    </form>
    <form name="message" method="post" action="">
    <textarea name="textarea"></textarea>
    </form>
    <form action="mass.php" method="post">
    <input type="submit" name="Submit" value="eMail Members">
    </form>
    </body>
    </html>
  • ForgeForge Senior Member The Royal RAM
    That could work bimmer. But i think i have an easier solution...
    <form action="mass.php" method="post">
    <input type="text" name="subject"> :: Subject<br>
    <textarea rows=5 cols=55 name="message">Message here</textarea><br>
    <input type="submit" value="Send Mass"><br>
    </form>
    

    Thats the forum that will take the info for the email...

    [php]

    <?

    $sqldb = "yourdb";
    $sqluser = "youruser";
    $sqlpass = "yourpass";
    $sqlhost = "localhost";

    $conn = mysql_connect("$sqlhost","$sqluser","$sqlpass");
    $sdb = mysql_select_db("$sqldb");

    $query = "SELECT * FROM tablewithemails";
    $result = mysql_query($query);

    while($row = mysql_fetch_assoc($result)){
    $member_name = $row[username];
    $member_email = $row[user_email];
    $message .= "\n\rThank you $member_name";
    mail($member_email, $subject, $message)

    }

    ?>

    [/php]

    I didnt have time to make it fancy. but that should work. Cheers..
    Can fat people Go skinny Dipping?
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    Forge, to be honest, I think it's the same :)

    Gavin, you've gotten your html all wrong. Anyway, Forge's html code should sort yours out.
  • ForgeForge Senior Member The Royal RAM
    I know its the same. Iono, I just was bored. Hehe
    Can fat people Go skinny Dipping?
  • GavinGavin Beginner Link Clerk
    how do i set the format out Forge?
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    Sir, if you want help, please at least try to ask with the proper details. What do you mean by "how do i set the format out"?

    What format? The HTML page format?
  • GavinGavin Beginner Link Clerk
    Sorry Sir, yes the HTML format thank you
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    This sure looks like you college/university homework... anyway, I'm a sucker...

    Try this for your html page:

    Note that:
    1. The name of the edit field ("subject") must match the $subject variable in your PHP file
    2. The name of the text area field ("message") must match the $message variable in your PHP file
    3. You need to name your PHP file as "mass.php" if you use "mass.php" in the form action
    <html>
    <body>
    <form name="subject" method="post" action="mass.php">
    Email Subject:<br>
    <input type="text" name="subject"><br>
    Email Message:<br>
    <textarea name="message"></textarea><br>
    <input type="submit" name="Submit" value="eMail Members">
    </form>
    </body>
    </html>
    
  • GavinGavin Beginner Link Clerk
    2 Questions, first of this works now :) thanks.

    1) how do i do a return message saying something like 'email(s) sent'
    2) how do i put the site name as the sender?

    -Gavin
  • aenigmaaenigma Beginner Link Clerk
    mmm, If the mailing is not so large you can use this method but If the mailing list if formed by lot of people I suggest you to export the user list and then use a dedicated softwre for mass-mailing. In this case I suggest You to use mach5mailer. I've used it with a mailing of 10.000 users, and worked out great.

    Link: http://www.mach5.com/
    Eremita Solitario
    http://www.thekey.it
Sign In or Register to comment.