Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9

Thread: Newsletter

  1. #1
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    I needed a custom mailing solution. So what I want to do is get info from a database and email it the names selected from the database.

    I have a table called members in that table are fields id, email, rank. For id its just auto_increments the number of members, email is obviously their email address and rank is currently either 1 or 2.

    What i need is a form that will allow me to select the rank or send to all say radio buttons to select 1, 2 or all. then a field to enter the newsletter. then click submit and send the newsletter to the people whos rank matches what i selected or to all members if i selected all.

    Please help I need this by 2morrow any help will be greatly appreciated. I know how to make it send to one person but not to multiple people.

    This is the form i need like this http://neonsonline.com/mailer.php just need to be able to make it send to a bunch of ppl depending on what group i choose. I just put this form together for a demo of what i need.

  2.  

  3. #2
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    I get a parse error. I'm a newbie and know what I wanna do but i have no idea on how to accomplish this so i cobbled this together. Can someone please help me out

    PHP Code:
    <?

    if ($submit) {

      
    // process form

    require ('../config.inc');

    if (
    $sendto == "1") {

    $db mysql_connect("$dbhost""$dbuser""$dbpassword"); 
    mysql_select_db("$dbname",$db);

    $result mysql_query("SELECT * FROM members WHERE rank = 1"$db);
    $mail mysql_fetch_array($result); 

    ;

    } elseif (
    $sendto == "2") {

    $db mysql_connect("$dbhost""$dbuser""$dbpassword"); 
    mysql_select_db("$dbname",$db);

    $result mysql_query("SELECT * FROM members WHERE rank = 2"$db);
    $mail mysql_fetch_array($result); 

    ;

    } elseif (
    $sendto == "all") {

    $db mysql_connect("$dbhost""$dbuser""$dbpassword"); 
    mysql_select_db("$dbname",$db);

    $result mysql_query("SELECT * FROM members"$db);
    $mail mysql_fetch_array($result); 

    ;
    }

    $email = ($mail["email"]);

        
    /* recipients */
        
    $to  "$email,";

        
    /* subject */
        
    $subject "$subject";

        
    /* message */
        
    $str="$body";

        
    $newstr=nl2br($str);
        
    $str="$story";

        
    $message "
        <head><style>
        a:link  {color : #9d0040; font-family: Arial; text-decoration: none; font-size: 12px;}
        a:visited  {color : #9d0040; font-family: Arial; text-decoration: none; font-size: 12px;}
        a:active  {text-decoration: none; font-family: Arial; font-size: 12px;}
        a:hover  {text-decoration: underline; color: #003d7c; font-family: Arial; font-size: 12px;}

        .main {
        font-size : 12px; 
        color : #000000; 
        font-family: Arial;
        }

        </style></head>
        <span class='main'>
        
        
    $newstr
        
        <p><center><img src=
    'http://glntax.com/images/dots_h.gif'><p>
        GLN Tax & 
    Payroll  427 West Fifth Street 
     Elmira, NY 14901  (607) 734-3164  <a href='http://glntax.com'>glntax.com</a>  <a 
    href='mailto:contact@glntax.com'>contact@glntax.com</a></center>
        </span>"
    ;
        
        
    /* To send HTML mail, you can set the Content-type header. */
        
    $headers  "MIME-Version: 1.0\r\n";
        
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

        
    /* additional headers */
        
    $headers .= "From: GLN Tax & Payroll <contact@glntax.com>\r\n";

        
    /* and now mail it */
        
    mail($to$subject$message$headers);

      echo 
    "<center><span class=\"main\"><b>Thank you for your interest in GLN Tax &
     Payroll! We will contact you A.S.A.P.</b></span>\n<p>
      </center>"
    ;

    } else{



      
    // display form
    ?>

    <p>
    <form method="post" action="<?php echo $PHP_SELF?>">

    <b>Send To</b><br>
    <input type="radio" name="sendto" value="1" checked> General Members<br>
    <input type="radio" name="sendto" value="2"> Media Members<br>
    <input type="radio" name="sendto" value="All"> All Members<br>
    <p>

    <b>E-Mail Subject</b><br>
    <input type=TEXT name="subject" value=""> <p>

    <b>E-Mail Body</b><br>
    <TEXTAREA NAME="body" ROWS="25" COLS="65"></TEXTAREA><p>

    <p>
    <input type="Submit" name="submit" value="Send News Letter" style="border:2px solid #851137;
     background-color: #8D9AC4; color: #002856; font-weight: bold">


    </FORM> 
    <?php



    // end if



    ?>

  4. #3
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    can anyone help out?

  5. #4
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    thats what i am having problems with

    http://neonsonline.com/mailer.php is an example of what i need. i need it to select a different set of users depending on what user group we want to send to

    we currently have a user group- 1, 2 and then if we chose all then it would send to all members no matter what group you are part of.

  6. #5
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    I changed a few things around. I dont get any parse errors but it doesnt send any mail either

    PHP Code:

    <?

    if ($submit) {

      
    // process form

    require "../config.inc";

    $db mysql_connect("$dbhost""$dbuser""$dbpassword"); 
    mysql_select_db("$dbname",$db);

    if (
    $sendto == "1") {
     
    $sql "SELECT * FROM members WHERE rank = 1";

    } elseif (
    $sendto == "2") {
      
    $sql "SELECT * FROM members WHERE rank = 2";

    } else {
      
    $sql "SELECT * FROM members";

    }

    $result mysql_query($sql);

    $email = ($result["email"]);

        
    /* recipients */
        
    $to  "$email,";

        
    /* subject */
        
    $subject "$subject";

        
    /* message */
        
    $str="$body";

        
    $newstr=nl2br($str);
        
    $str="$story";

        
    $message "
        <head><style>
        a:link  {color : #9d0040; font-family: Arial; text-decoration: none; font-size: 12px;}
        a:visited  {color : #9d0040; font-family: Arial; text-decoration: none; font-size: 12px;}
        a:active  {text-decoration: none; font-family: Arial; font-size: 12px;}
        a:hover  {text-decoration: underline; color: #003d7c; font-family: Arial; font-size: 12px;}

        .main {
        font-size : 12px; 
        color : #000000; 
        font-family: Arial;
        }

        </style></head>
        <span class='main'>
        
        
    $newstr
        
        <p><center><img src='http://glntax.com/images/dots_h.gif'><p>
        GLN Tax & Payroll  427 West Fifth Street  Elmira, NY 14901  (607) 734-3164 
    <a href='http://glntax.com'>glntax.com</a>  <a href='mailto:contact@glntax.com'>
    [email]contact@glntax.com[/email]</a></center>
        </span>"
    ;
        
        
    /* To send HTML mail, you can set the Content-type header. */
        
    $headers  "MIME-Version: 1.0\r\n";
        
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

        
    /* additional headers */
        
    $headers .= "From: GLN Tax & Payroll <contact@glntax.com>\r\n";

        
    /* and now mail it */
        
    mail($to$subject$message$headers);

      echo 
    "<center><span class=\"main\"><b>Thank you for your interest

    in GLN Tax & Payroll! We will contact you A.S.A.P.</b></span>\n<p>
      </center>"
    ;

    } else{



      
    // display form
    ?>

    <p>
    <form method="post" action="<?php echo $PHP_SELF?>">

    <b>Send To</b><br>
    <input type="radio" name="sendto" value="1" checked> General Members<br>
    <input type="radio" name="sendto" value="2"> Media Members<br>
    <input type="radio" name="sendto" value="All"> All Members<br>
    <p>

    <b>E-Mail Subject</b><br>
    <input type=TEXT name="subject" value=""> <p>

    <b>E-Mail Body</b><br>
    <TEXTAREA NAME="body" ROWS="25" COLS="65"></TEXTAREA><p>

    <p>
    <input type="Submit" name="submit" value="Send News Letter" style="border:2px
    solid #851137; background-color: #8D9AC4; color: #002856; font-weight: bold">


    </FORM> 
    <?php



    // end if



    ?>

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Have you tried to see if your server is properly configured to send mail?

    Try to upload a simple mail code (you can delete it afterwards) where you just assign values to the variables "$to, $subject, $textbody" and try sending it with the "mail()" function. Skip the $headers for now (they're anyway an optional argument to the "mail()" function.)

    If that works, we should look more closely at your code.
    If register_globals are set to "off" in your servers php.ini file, you need to use the superglobals $_POST['variable_name'] to get access to your posted values.
    Do you need to "SELECT * FROM" if you're just after your members email adresses? A shorter query runs faster.
    $subject="$subject";
    ??? When you reset variables, you don't need quotes. Additionally you are trying to set $subject to equal itself, which doesn't make sense.
    $result = mysql_query($sql);

    $email = ($result["email"]);
    $result is just a resultpointer, not an array. You can't extract values from it.
    You need to create an array containing your table data.
    mysql_fetch_array($result); will do that.
    However, only the first key of the array will be available. If you want all values (all email adresses), you need to iterate through the array with a "while" or "for" loop.

    You should also try to echo your values to browser first, to see that all variables are set properly if you encounter strange problems. That can save you a lot of misery. You remove the mail() function, and just echo the first 3-4 values of you array, to see that they actually exist.
    (for ($i=0; $i < 4; i++) {.....} ).

    Good luck.
    S. Rosland

  8. #7
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    i know it sends mail because its my server. keep in mind im a newbie. I have used this exact same script to send mail fromn my sites. the only thing now is that im trying to add this new feature to send mail to different people. look at the example http://neonsonline.com/mailer.php (this is just a demo to show what i need, not the actual script) but the radio boxes are what chooses the send to people. in my database i have id, email, rank and when you select on that form say user group 1 then it will send to all people with the rank of 1 and the same for 2 if user group 2 is selected then it will send to the people who's rank is 2. and lastly if the all members is chosen from the form then it will send to all people in the database no matter which rank they may be.

  9. #8
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Even if your mailserver works, the code comments still applies.

    Try echoing your variables to see what they output.
    In your first posted code, you generate an array. In the second, none.

    There's no iteration through the array in either one, which means stored array elements (email adresses in your case) won't populate strings to use in your mail() function.
    S. Rosland

  10. #9
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    i actually got it working

    thanks for ur help


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:45 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com