PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Email All Feature?

    Share

    theemonopolyguy

    Number of posts : 3
    Registration date : 2008-12-12

    Email All Feature?

    Post  theemonopolyguy on Wed Mar 04, 2009 8:21 pm

    I am a php n00b. I know the basic's, and no more than that. I love this script because it is very easy to use and understand.

    There is one feature I have been wanting to add tho, and it's an email all feature. Now I have some experience with sendmail, but can't seem to figure out how I woul get all the user's emails into on contact list.

    Any idea's?
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: Email All Feature?

    Post  Fred-Eric on Thu Mar 05, 2009 8:42 am

    Did you try a loop through all user's mail?

    theemonopolyguy

    Number of posts : 3
    Registration date : 2008-12-12

    Re: Email All Feature?

    Post  theemonopolyguy on Fri Mar 06, 2009 2:20 am

    Thats what I was thinking, something like a for loop. But how would you get each users email? I could probably figure out one, but all of them? Would you have to create some sort of method?

    I'm sorry. I know just the very very basics of PHP, and when i go to do something in php, i usually end up writing it in java...getting the two confused! (failing ap comp sci, but we're learning java)
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: Email All Feature?

    Post  Fred-Eric on Fri Mar 06, 2009 1:40 pm

    Add in the admin folder this file sendbulkmail.php

    Edited: march 7 2009.

    Code:

    <?
    /**
     * sendbulkmail.php
     *
     *
     * Written by: Fred-Eric Lafaille, fred-eric@lafaille.ca
     *
     * Last Updated: March 6 2009
     */
    include("../include/session.php");


    function GetEmailList(){
      global $database;
      $q = "SELECT email FROM ".TBL_USERS;
      $result = $database->query($q);

      $num_rows = mysql_numrows($result);
      if(!$result || ($num_rows < 0)){
          die ("Error gathering email list");
          return;
      }
      if($num_rows == 0){
          die ("Database table empty");
          return;
      }
      /* Display table contents */
     
     
      for($i=0; $i<$num_rows; $i++){

          $email  = mysql_result($result,$i,"email");

          echo "{$email}; ";
      }
     
    }

    function senbulkmail($email, $subject, $body){
       $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
       $email = trim($email);
       

       mail($email, $subject, $body, $from);

    return $email;
       
       
       
    }


     
    /**
     * User not an administrator, redirect to main page
     * automatically.
     */
    if(!$session->isAdmin()){
      header("Location: ../main.php");
    }
    else{
    /**
     * Administrator is viewing page, so display all
     * forms.
     */
    ?>
    <html>
    <head>
    <title>Jpmaster77's Login Script</title>
    <style type="text/css">
       h2{font-size: 1.2em;}
       label{display: block; font-weight: bold;}
    </style>
    </head>
    <body>

    <font size="4">Logged in as <b><? echo $session->username; ?></b></font><br><br>
    Back to [<a href="../main.php">Main Page</a>]<br><br>


    <br />
    <br />
    <?
    if (!isset($_REQUEST['alreadysend'])){
    ?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">

    <h2>Sending bulk mail</h2>
    <label for="to">to:</label>
    <textarea name="to" cols="50" rows="10"><?=GetEmailList();?></textarea>
    <label for="title">Subject</label>
    <input type="text" name="subject" size="40" value="subject here" />
    <br />
    <label for="body">body message</label>
    <textarea name="body" cols="50" rows="10">body here</textarea>

    <input type="hidden" value="1" name="alreadysend" />
    <br />
    <input type="submit" value="send" />
    </form>
    <?
    } else {

    $emailarray = explode(';', $_REQUEST['to']);
    print_r ($emailarray);

                   
     print 'successfully send mail to those users.<br />';       
    foreach ($emailarray as $key => $mail) {
       if($mail != " ")   print '<span style="font-family: courrier new;">['.senbulkmail($mail, $_REQUEST['subject'], $_REQUEST['body']). ']</span><br />';
    }



    ?>




    <input type="button" value="send an other mail" onclick="top.location.replace('<?=$_SERVER['PHP_SELF']?>');"/>

    <?
    }
    ?>
    </body>
    </html>
    <?
    }
    ?>


    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: Email All Feature?

    Post  Fred-Eric on Sat Mar 07, 2009 12:37 pm

    I don't know if this script will bulk mail with lots of users, I have only tested with 5 users and it is working fine.

    theemonopolyguy

    Number of posts : 3
    Registration date : 2008-12-12

    Re: Email All Feature?

    Post  theemonopolyguy on Mon Mar 09, 2009 3:08 pm

    Thanks for the help man, I appreciate it.This is exactly what I needed!

    Quick question, where did you learn all this, just kinda mess around and pick it up?

    Thanks again!

    I have build multiples websites since now with this login system, so maybe that's why I know it a little bit .
    avatar
    elvin66

    Number of posts : 24
    Registration date : 2009-03-13

    Re: Email All Feature?

    Post  elvin66 on Mon Mar 16, 2009 9:06 pm

    I have just set this email function up and got it almost working. My problem is two fold.
    1: Even though I have 3 users in the database (one being an admin account) only one email address receives the email (the other two do not).

    2: When my email comes through it has "Yourname" in the from field and "youremail@address.com" in the email field.

    I used include("../include/constants.php"); to make sure my admin email details were parsed through to the EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; fields but to no avail.

    Any ideas on this ???
    avatar
    s.w.vanderlaan

    Number of posts : 19
    Age : 38
    Localisation : The Netherlands
    Registration date : 2009-03-22

    Re: Email All Feature?

    Post  s.w.vanderlaan on Tue Apr 14, 2009 12:40 pm

    Hey,

    I need some help here. I've edited the sendbulkmail.php file. But I must be mssing something, because I get two messages:

    • Array ( [0] => ) Successfully send mail to those users.
    • No recipient addresses found in header []


    But I didn't sent anything yet. And there are recipient addresses in the "to" field...
    I just don't see a solution. Does anybody?

    Thanks,

    Sander
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Email All Feature?

    Post  Linchpin311 on Tue Apr 14, 2009 6:01 pm

    i wasnt able to reproduce this problem. where are you getting the No recipient addresses found in header [] error message? i dont see that in the original script. have you made any changes to this script? are you working from your localhost or from a live server?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    s.w.vanderlaan

    Number of posts : 19
    Age : 38
    Localisation : The Netherlands
    Registration date : 2009-03-22

    Re: Email All Feature?

    Post  s.w.vanderlaan on Wed Apr 15, 2009 3:02 am

    Hi,

    I have VAMP installed and also on a live server, both with Apache 2.2, PHP 5.2 and MySQL 5.2.

    I read yesterday something on how to use the mail function in php

    I did indeed change it a little, but only in the looks. Though I also changed the function sendbulkmail, but only so that I can send HTML-mail. When I use the original, it still giving the same error.

    Now I know, I don't have an e-mailserver installed on my VAMP (don't know how), but of course my webserver does have an e-mailserver, which works fine.

    I've pasted my adapted code below.

    Code:
    <?php
    /**
    * sendbulkmail.php
    *
    *
    * Originally written by: Fred-Eric Lafaille, fred-eric@lafaille.ca; Last Updated: March 6 2009
    *
    * Adapted by: Sander W. van der Laan
    * Last updated: April, 14 2009
    *
    */
    require_once("../_includes/session.php");
    function GetEmailList(){ 
       global $database; 
          $q = "SELECT email FROM ".TBL_USERS; 
          $result = $database->query($q); 
          $num_rows = mysql_numrows($result); 
             if(!$result || ($num_rows < 0)){     
             die ("Error gathering e-mail list.");     
             return; 
             } 
                if($num_rows == 0){     
                die ("Database table empty.");     
                return; 
                } 
    /* Display table contents */       
             for($i=0; $i<$num_rows; $i++){     
                $email  = mysql_result($result,$i,"email");
                   echo "{$email}; "; 
             } 
       }
    function sendbulkmail($email, $subject, $body){ 
       $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; 
       $email = trim($email);     
          mail($email, $subject, "<html><body>".$body."</body></html>",
             "".$from."\n" .
             "MIME-Version: 1.0\n" .
              "Content-type: text/html; charset=iso-8859-1");
       return $email;     

       }
    /**
    * User not an administrator, redirect to main page
    * automatically. */
    if(!$session->isAdmin()){ 
    header("Location: ../index.php");
    }
    else
    {
    /**
    * Administrator is viewing page, so display all * forms. */
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>The Aristot&eacute;lēs Project</title>
    <link href="../_styles/styles_oneColFixCtrHdr.css" rel="stylesheet" type="text/css" />
    <script src="spryassets/SpryMenuBar.js" type="text/javascript"></script>
    <script src="../_scripts/js_today.js" type="text/javascript"></script>
    <script type="text/javascript">
        _editor_url  = "http://www.waldamargroup.com/aristoteles/xinha/"  // (preferably absolute) URL (including trailing slash) where Xinha is installed
        _editor_lang = "en";      // And the language we need to use in the editor.
        _editor_skin = "silva";  // If you want use a skin, add the name (of the folder) here
    </script>
    <script src="http://www.waldamargroup.com/aristoteles/xinha/XinhaCore.js" type="text/javascript"></script>
    <script src="http://www.waldamargroup.com/aristoteles/xinha/my_config.js" type="text/javascript"></script>

    <link href="../spryassets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    </head>

    <body class="oneColFixCtrHdr">
       <div id="today"> 
          <?php include ("../_includes/today.inc"); ?>
        </div>
    <div id="container">
      <div id="header">
    <img src="../images/logo.png"/>
        <?php require_once ("../_includes/menuadmin.inc"); ?>
       <img src="../images/menugradient.png"/>
        <!-- end #header --></div>
      <div id="mainContent">
    <h1>Send E-mail to users</h1>
    You can write your e-mail using the form below and send it to all the users of The Aristot&eacute;lēs Project. Feel free to delete any of the selected e-mail addresses of any users.<br/><br/>
    <?php
    if (!isset($_REQUEST['alreadysend'])){
    ?>
    <form action="<?= $_SERVER['PHP_SELF']?>" method="POST">
    <label for="to"><i>Send to:</i></label><br/>
    <textarea name="to" id="to" class="textfield" style="width:90%" cols="50" rows="5" /><?= GetEmailList();?></textarea><br/>
    <label for="title"><i>Subject:</i></label><br/>
    <input type="text" name="subject" id="subject" class="textfield" style="width:90%" value="Your subject here, please" /><br />
    <label for="body"><i>Message</i></label><br/>
    <textarea name="body" id="body" class="textfield" style="width:90%" cols="50" rows="20" />Write your e-mail message here.</textarea>
    <input type="hidden" value="1" name="alreadysend" /><br />
    <input type="submit" name="Submit" id="Submit" value="Send e-mail" />
    </form>
    <?php
    } else
    ?>
    <font color="#FF9900">
    <?php
    {
    $emailarray = explode(';', $_REQUEST['to']);print_r ($emailarray);                 
          print '<br />Successfully send mail to these users.<br />';       
          foreach ($emailarray as $key => $email) { 
             if($email != " ") 
             print '['.sendbulkmail($email, $_REQUEST['subject'], $_REQUEST['body']). ']<br />';}
    }
    ?>
    <input type="button" value="Send an other mail" onClick="top.location.replace('<?=$_SERVER['PHP_SELF']?>');"/>
    <?php
    }?>
    </font>
       <!-- end #mainContent --></div>
      <div id="footer">
        <?php require_once('../_includes/footer.inc');?>
      <!-- end #footer --></div>
    <!-- end #container --></div>
       <div id="whologgedin">
        <?php include ("../_includes/whologgedin.inc"); ?>
        </div>
    <script type="text/javascript">
    <!--
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
    //-->
    </script>
    </body>
    </html>

    So, maybe you can see what it is about these messages, when I have NOT sent any mail yet:
    • Array ( [0] => )
    • Successfully send mail to these users.
    • No recipient addresses found in header []


    I think the last message has to do with the sendbulkmail function, the PHP-machine doesn't "see" the recipient addresses in the header of the e-mail, but ofcourse that's the maillist ($email). How do you figure that?

    Also, I was wondering what <?= means in a php statement like <?=$_SERVER['PHP_SELF']?>.

    Hoping you or Fred-Eric can help?

    Ciao,

    Sander
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Email All Feature?

    Post  Linchpin311 on Wed Apr 15, 2009 6:53 am

    in the send to: box are you seeing <?= GetEmailList();?> or can you see actual email addresses?

    well honestly, im thinking the <?=$_SERVER['PHP_SELF']?> is your problem.<?=$_SERVER['PHP_SELF']?> is the same as saying <?php echo $_SERVER['PHP_SELF']?> it just uses php's short tag notation. i know for a fact many WAMP servers dont play nice with php short tags. i would assume that some VAMP server configurations are effected by the same problem.

    also, and it looks like you already know this but, wamp (probably vamp as well) servers are a pain in the ass to correctly set up for smtp. so its best to test mail functions on a live server... unless you have taken the time to set the server up correctly and you know for a fact its working.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    s.w.vanderlaan

    Number of posts : 19
    Age : 38
    Localisation : The Netherlands
    Registration date : 2009-03-22

    Re: Email All Feature?

    Post  s.w.vanderlaan on Wed Apr 15, 2009 7:18 am

    Hi,

    I'm seeing actual e-mailadresses in the send to box.

    Than I'll change those short tags.

    Thanks so far.

    Sander

    Sponsored content

    Re: Email All Feature?

    Post  Sponsored content


      Current date/time is Sun Oct 22, 2017 4:55 pm