Jump to content

Recommended Posts

If I issue the following from my logon.php the mail get sent correctly

    $mailstring = date('Y-m-d H:i:s') . " ".$erroruser." Logged on from ". $client;
    $headers = 'From: es-master@stockton.co.za' . "\r\n" .
        'Reply-To: alf.stockton@telkomsa.net' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    mail("alf@stockton.co.za","Dinner Event",$mailstring,$headers);

but if I include it as

 
require_once('includes/error-handler.inc');

from the logon.php it does not work.

All variables are populated in both cases.

 

Please explain why this is happening.

Usually if I want to make it a .inc I'd make it a .inc.php

Same with most extensions. For classes I use .class.php

 

Absolutely!

 

Also, it may be worth mentioning that you MUST enclose the PHP portions of your .inc fine with PHP tags.

Just because you require/include it, does not mean it is included in PHP.

Actually, I believe the default for requiring/including a file acts like it is importing (X)HTML.

 

Just be sure to include those tags!

Those simple things happen to the best of us sometimes... :D

 

Ryan

.inc files will NOT be parsed unless you add the .inc as a php handler on the apache server.

if you have access to the system files on the server or using cPanel you can fix this.

if i have lost you then just rename the file to "error-handler.inc.php"

(infact i would do that in anycase)

When including/requiring a file through the file system, the file name does not matter for the include/require to function (it does matter if you put sensitive information into the file, such as a database username/password, because if it does not end in .php, someone can browse to it and see the php code in the file.)

 

If this was being done through a URL/http request, the file extension would matter and control if the file was parsed or not by php before being included into the current script.

it does not work.

 

Define: "it does not work". That could mean anything, such as a blank page because the require_once() failed because the path/file is incorrect and caused a fatal runtime error to your login no longer works because some white-space is preventing headers... What do you see in front of you when you do this?

I do not understand the ".inc files will NOT be parsed unless you add the .inc as a php handler on the apache server" as all other commands in the included file work fine. The included file contains a function which accepts a string as a parameter, builds a HTML page and also writes the string to a text file and then attempts to send an email, so saying it will not be parsed is going over my head and I do not understand.

It is just the mail() command that fails but if I include the same mail() call directly in the parent php it works fine.

BTW The "it does not work" means that the email is not sent.

<?php
// Thanks to http://www.tonymarston.net/php-mysql/errorhandler.html
// set_error_handler('errorHandler');

function get_sql_error($sQuery, $hDb_conn, $sError, $bDebug)
{
   if(!$rQuery = @mysql_query($sQuery, $hDb_conn))
   {
       $sMssql_get_last_message = mysql_get_last_message();
       $sQuery_added  = "BEGIN TRY\n";
       $sQuery_added .= "\t".$sQuery."\n";
       $sQuery_added .= "END TRY\n";
       $sQuery_added .= "BEGIN CATCH\n";
       $sQuery_added .= "\tSELECT 'Error: '  + ERROR_MESSAGE()\n";
       $sQuery_added .= "END CATCH";
       $rRun2= @mysql_query($sQuery_added, $hDb_conn);
       $aReturn = @mysql_fetch_assoc($rRun2);
       if(empty($aReturn))
       {
           echo $sError.'. MYSQL returned: '.$sMysql_get_last_message.'.<br>Executed query: '.nl2br($sQuery);
       }
       elseif(isset($aReturn['computed']))
       {
           echo $sError.'. MYSQL returned: '.$aReturn['computed'].'.<br>Executed query: '.nl2br($sQuery);
       }
       return FALSE;
   }
   else
   {
       return $rQuery;
   }
}

function errorHandler ($errno, $errstr)
        {
// echo "<br>Entered errorHandler()<br>";
// echo $errno." ".$errstr;
        switch ($errno)
            {
            case E_USER_WARNING:
            case E_USER_NOTICE:
            case E_WARNING:
            case E_NOTICE:
            case E_CORE_WARNING:
            case E_COMPILE_WARNING:
                     break;
            case E_USER_ERROR:
            case E_ERROR:
            case E_PARSE:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
                global $query;
                echo '<html xmlns="http://www.w3.org/1999/xhtml">';
                echo '<head>';
                echo '<title>Message</title>';
                echo '<style>';
                echo '<!--';
                echo '.normalcopy { font-family: Verdana, Arial; font-size: 11px; color: Black; }';
                echo '.bottomlinks { color: #666666; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight:
normal; text-decoration: none; }';
                echo '-->';
                echo '</style>';
                echo '</head>';
                echo '<body bgcolor="#ffffff">';

                $errorstring = "<align=center>" .date('Y-m-d H:i:s') ."";
//                $errstr .= " " . $erroruser;

                echo '<center>';
                echo '<table border="0" cellpadding="0" cellspacing="0" width="748">';
                echo '<tr>';
                echo '<td align left = "" valign="top" height="73" class="normalcopy">';
                echo '<p align="center"><strong>'.$errstr.'</p>';
                echo '</td></align></tr>';
                echo '</table>';
                echo '</center>';

                $logfile = "errorlog.html";
                $client  = $_SERVER['REMOTE_ADDR'];
                $errorstring .= " ";
                $errorstring .= $errstr;
                $errorstring .= " on ";
                $errorstring .= $client;
                $errorstring .= " by ";
                $errorstring .= $erroruser;
                $errorstring .= "<br>";
                $Boodskap = "<br><align=left>" . date('Y-m-d H:i:s') . " " . $errstr;
                error_log($Boodskap, 3, $logfile);
    $headers = 'From: es-master@stockton.co.za' . "\r\n" .
        'Reply-To: alf.stockton@telkomsa.net' . "\r\n"; 
    mail("alf@stockton.co.za","Error log",$Boodskap,$headers);

            default:
                break;
            } // switch

//        get_sql_error($insert, $link, NULL, NULL);
//        echo "<a href=index.php><img src=images/Back.png>";
        echo "</BODY>";
        echo "</HTML>";
    } // errorHandler
?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.