Welcome Guest, Not a member yet? Register   Sign In
Weird behaviour of mail() function
#1

[eluser]verisof[/eluser]
Hi all, I found a very strange thing, hope someone can explain this.

I had a problem with sending email via Email class. It was always ending with FALSE when it came to mail(...) part. So I tried to put my testing simple mail() function to different places.

I used this test code:

Code:
mail("[email protected]","testmessage","testmessage")

1) When I put it to index.php before the first CI code, it worked
2) When I put it to codeigniter/CodeIgniter.php after sending all the output, it worked
3) When I put it to my controller class before the parent::Controller(); call in the constructor, it worked
4)And finally, when I put it anywhere after the parent::Controller(); call (just after it, in some function, anywhere in the Email class it didn't work

(when I say it worked, it means that the email arrived and thu function returned TRUE)

I must add, that I never changed anything "inside" CI or Email class. It seems that right after parent::Controller(); call, the mail() function stops working. I searched my project to find out if I didn't override it by an accident, but nothing like this happened.

I used Email class to send emails succesfully before, but now I can't say what is going on.

Any idea someone?
#2

[eluser]drewbee[/eluser]
You say it doesn't work when you put it in the parent construct class? Are you calling the parent constructor upon adding the child construct??


Code:
class ParentClass
{
    function __construct()
    {
         mail();
    }
}

// Now extend it...
class ChildClass extends ParentClass
{
    // Does not work, you are overloading the parent __constructor method.
    function __construct()
    {
         // To get the original parent constructor to fire, you must explicitly call it
         // Now we should send out mail.
         parent::__construct();
    }
}

Or you can explicitly leave the __construct() method out of the child class to which it will not over overload it.

Why is this posted in the bug reports? This would be more specific to PHP, not Code Igniter if it were an issue;

P.S. Welcome to Code Igniter Smile
#3

[eluser]verisof[/eluser]
[quote author="drewbee" date="1241732706"]You say it doesn't work when you put it in the parent construct class? Are you calling the parent constructor upon adding the child construct??[/quote]

No, I say that it doesn't work when I call contructor of parent ->Controller<- (which is why I posted it to bugs). My code is:

This works:
Code:
class Home extends Controller {
function __construct () {
        mail(...);
        parent::Controller();
}
}


And this DOESN'T work:
Code:
class Home extends Controller {
function __construct () {
        parent::Controller();
        mail(...);
}
}

If anyone has an idea what can be the problem or where could I have done something wrong, that it influence this part of code, please let me know. This problems concerns about controllers in CI, about it's conctruction. I don't know, what can cause such a strange behaviour. Thanks
#4

[eluser]drewbee[/eluser]
Ok I see what you are doing, and this should not matter. I can't touch any code at the moment but I will see if I can replicate this when I get home. If anyone else has a free minute...




Theme © iAndrew 2016 - Forum software by © MyBB