The problem is that when the fallback function is called by doing receiver.transfer() it will not have the necessary gas to modify the state variable.
According to Solidity docs:
In such a context, there is usually very little gas available to the
function call (to be precise, 2300 gas), so it is important to make
fallback functions as cheap as possible. Note that the gas required by
a transaction (as opposed to an internal call) that invokes the
fallback function is much higher, because each transaction charges an
additional amount of 21000 gas or more for things like signature
checking.
In particular, the following operations will consume more gas than the
stipend provided to a fallback function:
Writing to storage
Creating a contract
Calling an external function which consumes a large amount of gas
Sending Ether
If you wanted to have your Sender contract to transfer ether to the Receiver contract, instead of calling receiver.transfer you should implement a function in Receiver that receives ether, like so:
contract Sender {
function() payable{
}
function sendTo(address receiverAddr) payable {
var receiver = Receiver(receiverAddr);
receiver.payMe.value(msg.value)();
}
}
contract Receiver {
bool public received;
function() payable{
}
function payMe() payable returns(bool success) {
received = true;
return true;
}
}