Heat the oil in a large saucepan over a medium heat and cook the onion for 5-10 minutes, until soft. Add the mushrooms and courgettes and cook for a further 5 minutes, until golden, adding the garlic for the last minute. Meanwhile, cook the spaghetti according to the instructions on the packet.
In a separate bowl, lightly whisk the egg yolks, milk and cream. Stir in half the grated cheese.
Drain the spaghetti and return to the pan. Stir through the ham, the vegetable mixture and the creamy sauce. Toss together well.
Return to the heat for 1-2 minutes and toss until cooked through. Season well and sprinkle over the remaining cheese to serve.