Welcome to Geeklog, Anonymous Tuesday, March 19 2024 @ 05:35 am EDT

Geeklog Forums

Mail function differences


ironmax

Anonymous
I've been banging my head on why users can't send email from certain parts of geeklog. I ran some tests for new user signups and they went thru just fine as intended. So I know http://www.spacequad.com/users.php?mode=new works just fine. So then I was asked to check if mail users, http://www.spacequad.com/admin/mail.php worked and sorry to say, it came up with an error. Fatal error: Class 'Mail' not found in E:\spacequad\public_html\lib-common.php on line 2993. I then checked it to find out why it wasn't finding the pear mail routine. Did some further test to see if I can run mail instead of smtp from the config.php file and I could not because of security issues. Thats why I didn't go that route, but the mail.php in the pear dir was found and worked, but with running the risk of an open SMTP mailer. Anyways, I looked at profiles.php in the public dir and found that that mail function routine works for me...however, the one that is in admin/mail.php does not. I noticed that the mail function at the bottom file is as follows

Text Formatted Code

// MAIN

$display .= COM_siteHeader ('menu', $LANG31[1]);

if (isset ($_POST['mail']) && ($_POST['mail'] == 'mail')) {
    $display .= send_messages ($_POST);
} else {
    $display .= display_form ();
}

$display .= COM_siteFooter ();
 


Is that right? How are the variables plugged in?
I don't know if I explained it good enough here or not.

Michael

So new user work
Forum emails work
private msg emails do NOT work
Geeklog's Mail users do NOT work
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
I have a vague recollection of this being discussed back when we started using PEAR for emails. So I thought this had long been resolved - but maybe not.

The problem, AFAIR, was that the include_once for Mail.php (the PEAR class) would try to load mail.php (from Geeklog's admin directory) on a non-case sensitive file system since it checks the current directory first. The include_once prevents it from actually being loaded but it's then still missing the PEAR class "Mail".

Now that I think about it, I'm not sure how (or if) that was ever resolved. Only that I sure haven't heard about this in a while. Maybe because nobody uses Windows to host their site :wink:

bye, Dirk
 Quote

ironmax

Anonymous
Is there away that this can be fixed?


Michael
 Quote

Status: offline

beandip

Forum User
Newbie
Registered: 11/10/04
Posts: 12
Okay... I'm a bit disheartened to see that there has been no resolution to this post.

I was under the illusion that email had been working fine from my geeklog site. However it appears email works fine UNLESS you try to use the admin/mail.php tool. When I send a message, I get a plain white web page with no errors. checking my logs I get the following message:

[error] PHP Fatal error: Class 'Mail' not found in /Library/WebServer/Documents/lib-common.php on line 2994

OS = Mac OS 10.4.9
Apache 1.3.33
PHP 5.2.1

In my config.php I have the following set:

Text Formatted Code

// If your server is running PHP 4.3.0 (or newer) then chances are that PEAR
// is already installed and you can change this to: $_CONF['have_pear'] = true;
$_CONF['have_pear'] = false;

// Geeklog comes with the necessary PEAR packages and will pick them up from
// the following directory if $_CONF['have_pear'] = false (above).
$_CONF['path_pear'] = $_CONF['path_system'] . 'pear/';
 


Oh yeah and I'm running Geeklog 1.4.1

I know that this has worked for me in the past, but it has been awhile and I believe I have upgraded to PHP 5 since then...

Any ideas?

 Quote

ironmax

Anonymous
Windows OS doesn't recognize the differences between upper and lower case in programming. I also suspect some other OS's as well. The characters are all treated the same for upper and lower case. Atleast thats what I've discovered. Once a file name has been loaded into memory for an include statement, no matter what the path, that file name with different content, cannot be called from someplace else and expect to work. I had to fixed this internally by changing the file name in a few places to make it work.

1. You will need to change /public_html/admin/mail.php file name to something other than mail.php. That file name is used for pear's mail function. Hence the conflict. I used the new file name of adminmail.php. You will also need to make name changes internally to reflect the name change as well. Look at code to make your changes below. Or you can just copy and paste this first code section into a new file called adminmail.php.

Text Formatted Code

<?php

/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4                                                               |
// +---------------------------------------------------------------------------+
// | adminmail.php                                                             |
// |                                                                           |
// | Geeklog mail administration page.                                         |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2001-2006 by the following authors:                         |
// |                                                                           |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com                           |
// |          Dirk Haun  - dirk AT haun-online DOT de                          |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+
//
// $Id: adminmail.php,v 1.32 2006/02/26 18:12:10 dhaun Exp $

require_once ('../lib-common.php');
require_once ('auth.inc.php');

$display = '';

// Make sure user has access to this page  
if (!SEC_inGroup ('Mail Admin') && !SEC_hasrights ('user.mail')) {
    $retval .= COM_siteHeader ('menu', $MESSAGE[30]);
    $retval .= COM_startBlock ($MESSAGE[30], '',
                               COM_getBlockTemplate ('_msg_block', 'header'));
    $retval .= $MESSAGE[39];
    $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
    $retval .= COM_siteFooter ();
    COM_accessLog ("User {$_USER['username']} tried to illegally access the mail administration screen.");
    echo $retval;
    exit;
}

/**
* Shows the form the admin uses to send Geeklog members a message. Right now
* you can only email an entire group.
*
* @return   string      HTML for the email form
*
*/
function display_form ()
{
    global $_CONF, $_TABLES, $_USER, $LANG31;

    $retval = '';

    $mail_templates = new Template ($_CONF['path_layout'] . 'admin/mail');
    $mail_templates->set_file (array ('form' => 'mailform.thtml'));
    $mail_templates->set_var ('site_url', $_CONF['site_url']);
    $mail_templates->set_var ('site_admin_url', $_CONF['site_admin_url']);
    $mail_templates->set_var ('layout_url', $_CONF['layout_url']);
    $mail_templates->set_var ('startblock_email', COM_startBlock ($LANG31[1],
            '', COM_getBlockTemplate ('_admin_block', 'header')));
    $mail_templates->set_var ('php_self', $_CONF['site_admin_url']
                                          . '/adminmail.php');
    $mail_templates->set_var ('lang_note', $LANG31[19]);
    $mail_templates->set_var ('lang_to', $LANG31[18]);
    $mail_templates->set_var ('lang_selectgroup', $LANG31[25]);
    $group_options = '';
    $result = DB_query("SELECT grp_id, grp_name FROM {$_TABLES['groups']} WHERE grp_name <> 'All Users'");
    $nrows = DB_numRows ($result);
    $groups = array ();
    for ($i = 0; $i < $nrows; $i++) {
        $A = DB_fetchArray ($result);
        $groups[$A['grp_id']] = ucwords ($A['grp_name']);
    }
    asort ($groups);
    foreach ($groups as $groupID => $groupName) {
        $group_options .= '<option value="' . $groupID . '">' . $groupName
                       . '</option>';
    }
    $mail_templates->set_var ('group_options', $group_options);
    $mail_templates->set_var ('lang_from', $LANG31[2]);
    $mail_templates->set_var ('site_name', $_CONF['site_name']);
    $mail_templates->set_var ('lang_replyto', $LANG31[3]);
    $mail_templates->set_var ('site_mail', $_CONF['site_mail']);
    $mail_templates->set_var ('lang_subject', $LANG31[4]);
    $mail_templates->set_var ('lang_body', $LANG31[5]);
    $mail_templates->set_var ('lang_sendto', $LANG31[6]);
    $mail_templates->set_var ('lang_allusers', $LANG31[7]);
    $mail_templates->set_var ('lang_admin', $LANG31[8]);
    $mail_templates->set_var ('lang_options', $LANG31[9]);
    $mail_templates->set_var ('lang_HTML', $LANG31[10]);
    $mail_templates->set_var ('lang_urgent', $LANG31[11]);
    $mail_templates->set_var ('lang_ignoreusersettings', $LANG31[14]);
    $mail_templates->set_var ('lang_send', $LANG31[12]);
    $mail_templates->set_var ('end_block', COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer')));

    $mail_templates->parse ('output', 'form');
    $retval = $mail_templates->finish ($mail_templates->get_var ('output'));

    return $retval;
}

/**
* This function actually sends the messages to the specified group
*
* @param    array   $vars   Same as $_POST, holds all the email info
* @return   string          HTML with success or error message
*
*/
function send_messages ($vars)
{
    global $_CONF, $_TABLES, $LANG31;

    $retval = '';

    if (empty ($vars['fra']) OR empty ($vars['fraepost']) OR
            empty ($vars['subject']) OR empty ($vars['message']) OR
            empty ($vars['to_group'])) {
        $retval .= COM_startBlock ($LANG31[1], '',
                        COM_getBlockTemplate ('_msg_block', 'header'));
        $retval .= $LANG31[26];
        $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));

        return $retval;
    }

    // Urgent message!
    if (isset ($vars['priority'])) {
        $priority = 1;
    } else {
        $priority = 0;
    }

    // If you want to send html mail
    if (isset ($vars['html'])) {
        $html = true;
    } else {
        $html = false;
    }

    // and now mail it
    if (isset ($vars['overstyr'])) {
        $sql = "SELECT username,fullname,email FROM {$_TABLES['users']},{$_TABLES['group_assignments']} WHERE uid > 1";
        $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))";
        $sql .= " AND {$_TABLES['users']}.uid = ug_uid AND ug_main_grp_id = {$vars['to_group']}";
    } else {
        $sql = "SELECT username,fullname,email,emailfromadmin FROM {$_TABLES['users']},{$_TABLES['userprefs']},{$_TABLES['group_assignments']} WHERE {$_TABLES['users']}.uid > 1";
        $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))";
        $sql .= " AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND emailfromadmin = 1";
        $sql .= " AND ug_uid = {$_TABLES['users']}.uid AND ug_main_grp_id = {$vars['to_group']}";
    }

    $result = DB_query ($sql);
    $nrows = DB_numRows ($result);

    $from = COM_formatEmailAddress ($vars['fra'], $vars['fraepost']);
    $subject = COM_stripslashes ($vars['subject']);
    $message = COM_stripslashes ($vars['message']);

    // Loop through and send the messages!
    $successes = array ();
    $failures = array ();
    for ($i = 0; $i < $nrows; $i++) {
        $A = DB_fetchArray ($result);
        if (empty ($A['fullname'])) {
            $to = COM_formatEmailAddress ($A['username'], $A['email']);
        } else {
            $to = COM_formatEmailAddress ($A['fullname'], $A['email']);
        }

        if (!COM_mail ($to, $subject, $message, $from, $html, $priority)) {
            $failures[] = htmlspecialchars ($to);
        } else {
            $successes[] = htmlspecialchars ($to);
        }
    }

    $retval .= COM_startBlock ($LANG31[1]);

    $failcount = count ($failures);
    $successcount = count ($successes);
    $mailresult = str_replace ('<successcount>', $successcount, $LANG31[20]);
    $retval .= str_replace ('<failcount>', $failcount, $mailresult);

    $retval .= '<h2>' . $LANG31[21] . '</h2>';
    for ($i = 0; $i < count ($failures); $i++) {
        $retval .= current ($failures) . '<br>';
        next ($failures);
    }
    if (count ($failures) == 0) {
        $retval .= $LANG31[23];
    }

    $retval .= '<h2>' . $LANG31[22] . '</h2>';
    for ($i = 0; $i < count ($successes); $i++) {
        $retval .= current ($successes) . '<br>';
        next ($successes);
    }
    if (count ($successes) == 0) {
        $retval .= $LANG31[24];
    }

    $retval .= COM_endBlock ();

    return $retval;
}

// MAIN

$display .= COM_siteHeader ('menu', $LANG31[1]);

if (isset ($_POST['mail']) && ($_POST['mail'] == 'mail')) {
    $display .= send_messages ($_POST);
} else {
    $display .= display_form ();
}

$display .= COM_siteFooter ();

echo $display;

?>
 


2. You will also need to make one change in the /public_html/lib-common.php file on approx line 2447. Listed below.

Text Formatted Code

        if( SEC_hasRights( 'user.mail' ))
        {
            $url = $_CONF['site_admin_url'] . '/adminmail.php';
            $adminmenu->set_var( 'option_url', $url );
            $adminmenu->set_var( 'option_label', $LANG01[105] );
            $adminmenu->set_var( 'option_count', 'N/A' );

            $menu_item = $adminmenu->parse( 'item',
                    ( $thisUrl == $url ) ? 'current' : 'option' );
            $link_array[$LANG01[105]] = $menu_item;
        }
 


Save it all off and it will now work as intended.

Michael
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
IMO, this should be checked into CVS. There should not be too many people with bookmarks in the admin area.
 Quote

Status: offline

beandip

Forum User
Newbie
Registered: 11/10/04
Posts: 12
Thanks Ironmax...

I wonder what the various factors are as it used to work fine... are you running PHP5 as well?

I did what you suggested and now it works great on my OS X (10.4.9) box.

Thanks!
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
The problem here is the PHP devs have said this is not their problem:
include_once documentation at php.net

Note: Be aware, that the behaviour of include_once() and require_once() may not be what you expect on a non case sensitive operating system (such as Windows).


This is why I think we need to code around it or drop Windows support.
 Quote

ironmax

Anonymous
Quote by: jmucchiello

The problem here is the PHP devs have said this is not their problem:

include_once documentation at php.net

Note: Be aware, that the behaviour of include_once() and require_once() may not be what you expect on a non case sensitive operating system (such as Windows).


This is why I think we need to code around it or drop Windows support.



Then you might as well say its for NIX systems only, nice one.. So Pear beat Geeklog to the name game on mail.php, big deal. Solution....just rename the file!!!!
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Solution....just rename the file!!!!
And find all the references to the old name and fix them. It is a simple fix, but it's not a no brainer fix.

Maybe we should take this one up with the PEAR folks. Naah, they'd probably say it not their problem, too.
 Quote

ironmax

Anonymous
Quote by: jmucchiello

Solution....just rename the file!!!!
And find all the references to the old name and fix them. It is a simple fix, but it's not a no brainer fix.

Maybe we should take this one up with the PEAR folks. Naah, they'd probably say it not their problem, too.



Whatever! I came up with a simple fix that we all could live with to make it work for all OS's, and I get this for trying to help someone else out that had the same problem I had on a windows server. Then to find out that its not isolated. Mac OS, seems to be having the same issue. Thats 2 OS's now...how many more?

 Quote

Status: offline

beandip

Forum User
Newbie
Registered: 11/10/04
Posts: 12
I'd have to agree with Ironmax... (but then I'm using an affected OS)

While changing the filename in the main distribution could be time consuming I think it would make sense in terms of the longevity of the product. I've always thought one of Geeklog's big strengths was its platform independence.

I'd still like to know what the second factor is that leads to this particular mail.php issue. Mine worked fine for many years until recently and the only big thing I can think of would be the upgrade to PHP 5.

Thanks again for the fix.
 Quote

All times are EDT. The time is now 05:35 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content