Part of the EllisLab Network
   
 
Incorrect safe_mode check in Email.php
Posted: 18 January 2007 02:48 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  41
Joined  07-07-2006

Guys, another bug fix for 1.5.1. Found the following problem in library Email.php:

Line 120:

$this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE;

Our application is running in SAFE_MODE and can’t send email’s. This is because safe mode restricts the mail() function from using the fifth parameter:

function _send_with_mail()
    
{    
        
if ($this->_safe_mode == TRUE)
        
{
            
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
                return
FALSE;
            else
                return
TRUE;        
        
}
        
else
        
{
            
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f".$this->clean_email($this->_headers['From'])))
                return
FALSE;
            else
                return
TRUE;
        
}
    }

Conclusion: the safe_mode check is incorrect. init_get can also return a string “On”.  The correct code would be:

$this->_safe_mode = (@ini_get("safe_mode") == 'On' || @init_get("safe_mode") === 1) ? TRUE : FALSE;
Profile
 
 
Posted: 18 January 2007 03:20 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  303
Joined  10-17-2006

I ran into the same problem. Thanks for the fix. I fixed by emailing my host to disable Safe_mode smile

Profile
 
 
Posted: 18 January 2007 03:23 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  41
Joined  07-07-2006
nmweb - 18 January 2007 03:20 AM

I ran into the same problem. Thanks for the fix. I fixed by emailing my host to disable Safe_mode smile

Well, you can mail your host again :-p With this fix you can turn it on again. Makes your site a lot safer grin

Profile
 
 
Posted: 08 June 2007 09:04 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  15
Joined  01-12-2007

I have the same problem : Code Igniter seems not to detect if safe mode is enabled or not. Then CI is unable to send email with the correct parameters according to the safe mode status.

I found a workaround found by pk1 in this thread but I’d like to find the real problem and correct it for the next release of Code Igniter.

Anyone can help me in tracking this bug ?

Profile
 
 
Posted: 08 June 2007 12:59 PM   [ Ignore ]   [ # 4 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7515
Joined  08-05-2002

ini_get() and Safe Mode ini setting

“When querying boolean values: A boolean ini value of off will be returned as an empty string or “0” while a boolean ini value of on will be returned as “1”.”

Are you telling me that the PHP documentation is incorrect (again?!) and that sometimes @ini_get(“safe_mode”) will return Off and On instead of the boolean 1 or 0 (or an empty string)?  I love this language, I really do, but sheesh.  Please confirm and we can make this change in the next version.

 Signature 


♖  ♘  ♗  ♔  ♕  ♗  ♘  ♖
♙  ♙  ♙  ♙  ♙  ♙  ♙  ♙
☐  ☐  ☐  ☐  ☐  ☐  ☐  ☐
☐  ☐  ☐  ☐  ☐  ☐  ☐  ☐
☐  ☐  ☐  ☐  ☐  ☐  ☐  ☐
☐  ☐  ☐  ☐  ☐  ☐  ☐  ☐
♟  ♟  ♟  ♟  ♟  ♟  ♟  ♟
♜  ♞  ♝  ♚  ♛  ♝  ♞  ♜

Profile
 
 
Posted: 08 June 2007 04:35 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  15
Joined  01-12-2007

My host is Free.fr, the french ISP.

I made a small test file which code is :

<?php
echo @ini_get("safe_mode");
?>

And I get the following result :

1

But the problem still remains, I cannot send email as the wrong method is used, as if safe mode was notenabled (but is it !).

There is another problem in the way the Email library handle the safe mode parameter to send emails…

Profile
 
 
Posted: 16 October 2007 04:43 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  303
Joined  10-17-2006

I encountered this problem again. The problem seems not to be the checking of the .ini whether safe mode is on, that this

$this->_safe_mode = (@ini_get("safe_mode")==1) ? TRUE : FALSE;

is not the problem. This line is, however, never called unless you call $this->email->initialize(); yourself. The problem is solved when you move the aforementioned line to the constructor or perhaps a better place the email::send() function. Fact is that in 1.5.4 the problem is not yet solved, also in the current svn it is not yet fixed.

Please fix this, I think it’s causing many problems for those facing safe mode.

Profile
 
 
Posted: 20 November 2007 02:01 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  1
Joined  11-20-2007

There’s better solution

if (count($config) > 0)
        
{
            $this
->initialize($config);
        
}

Find those lines and delete “if” with everything leaving only

$this->initialize($config);

I don’t know why to do that count thing as default initialization goes with 0 size of array as well as $this->initialize as well accepts 0 size array or even without parameters. Fixing like this blew away all my problems smile

Profile
 
 
Posted: 17 February 2008 02:34 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  493
Joined  02-21-2007

http://codeigniter.com/bug_tracker/bug/3057/

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 114897 Total Logged-in Users: 37
Total Topics: 122389 Total Anonymous Users: 2
Total Replies: 647052 Total Guests: 362
Total Posts: 769441    
Members ( View Memberlist )