Patrick Marleau and Dan Boyle had two assists each and backup goalie Thomas Greiss stopped 37 shots for the Sharks, who won for the fourth time in five games to complete a 4-2 road trip.
Darroll Powe scored the lone goal for the Flyers, who had their two-game winning streak snapped.
Philadelphia goalie Brian Boucher stopped 24 shots in his first start of the season. Boucher, who played for the Sharks last season, started for the Flyers for the first time in more than seven years. He made his debut with Philadelphia in 1999 and has played for five NHL teams since then.
Flyers captain Mike Richards was in the lineup after having been cleared by the NHL for a hard hit on Florida left wing David Booth in a 5-1 win over the Panthers on Saturday. Booth left the ice on a stretcher with 2:55 left in the second period following a blow to the face. He was transported to an area hospital and remained overnight for tests before being released on Sunday.
The Sharks went ahead 2-1 at 7:51 of the second period on Malhotra's first goal of the season. The puck deflected off Boucher's stick and into the net.
Malhotra struck again slightly more than 2 minutes later with his second goal. With 9:55 left, Malhotra's wrist shot from above the faceoff circle beat Boucher for a 3-1 advantage. Ortmeyer completed the scoring with a turnaround wrist shot with 3:09 left.
San Jose took a 1-0 lead when Heatley scored his eighth goal of the season, a power-play goal at 6:20 of the first period. Joe Thornton and Boyle registered assists on Heatley's goal as he capitalized on a second chance in front of Boucher.
The Flyers tied the game at 9:44 of the first. Mika Pyorala earned his first NHL point with a pass to Powe, who sent a one-timer from above the slot into the net.
Notes: Flyers C Danny Briere played in his 600th career game. ... San Jose improved to 7-0 when leading after two periods. ... The Flyers recalled defenseman Oskars Bartulis from the Adirondack Phantoms of the American Hockey League. Bartulis has two goals and one assist in eight games with the Phantoms this season. ... San Jose played without RWs Devin Setoguchi and Ryan Vesce. Both players suffered leg injuries in Saturday's 4-3 win at Atlanta and are considered day-to-day.