I was fighting a flesh golem, and attacked with a weapon enchanted with electricity, does this trigger the golem's immunity to magic effect?
Does attacking with an enchanted weapon count as a magic attack?
Your weapon is still a physical object that physically hits the golem, and deals a certain amount of physical (bludgeoning, piercing, and/or slashing) damage. That doesn’t change just because the weapon is also magical and deals magical electricity damage. So even though the flesh golem is immune to magic, you still deal the physical damage of your weapon.
That includes the enhancement bonus of the weapon, by the way. Enhancement bonuses improve the weapons (making them sharper or harder-hitting or whatever), they don’t directly deal magical damage. So if you have a +1 longsword it will deal 1d8+1 (plus whatever other bonuses you have like Strength).
The big question is about your electricity damage and the golem’s “immunity to magic” in the first place. Immunity to magic doesn’t actually make you immune to magic. It’s more like infinite spell resistance. Things that ignore spell resistance—SR: No spells and spell-like abilities, or magic that is not a spell or spell-like ability—ignores it entirely.
A flesh golem is immune to any spell or spell-like ability that allows spell resistance.
So even though the electricity damage of a magic weapon is magic, it is not a spell or spell-like ability, and is not impeded by spell resistance—which means it would not have any problem with the golem’s immunity to magic. That much is clear.
But then we get to these bullet points about cold or fire damage and electricity damage. Your attack is dealing magical electricity damage, which seems to mean that, even though it isn’t blocked by the flesh golem’s immunity to magic, that function should still trigger. What that means is kind of debatable: being strictly literal, it would imply that you deal your electricity damage, and then the golem is un-slowed and healed for a little bit of that damage. Though the healing is based on “damage the attack would otherwise deal,” which could arguably mean that magical electricity damage doesn’t harm a flesh golem even if from something that’s not a spell or spell-like ability, or it could mean that if a form of magical electricity damage isn’t blocked, it doesn’t trigger healing.
You will have to ask your GM about that.