I am not sure about MacBook Air, but in my MacBook Pro (Mid 2010) it will charge my iPhone if the MB is active (powered up and not sleeping) and it will also charge my iPhone when sleeping, but only if the iPhone was plugged in before the MB went to sleep.
If your MB is shut down (not active & not sleeping) it will not charge your iPhone.
UPDATE
One of OS X/MacBook updates must have changed something at some point. Now, when a MacBook is plugged and sleeping and you plug in an iPhone, the MacBook will silently wake up, start charging the iPhone and fall back to sleep. It all happens with closed lid.
It is possible that there is a problem with the port on the computer, either with the device now being blocked (which is sometimes done via policy in enterprise environments) or the port malfunctioning/disabled altogether. Do other devices, such as flash drives, work if you plug them into the same USB port you were using with your iPhone?
If no devices are working in the port, try the following:
Windows/Mac Desktop/Macbook w/ removeable battery:
1) Shut down the computer
2) Unplug all items from the computer, including power
3) Press and hold down on the power button for ~7 seconds
4) Plug power back in
5) Plug other devices back in
6) Start up and see if the port has started to work again
Macbook without removable battery:
1) Turn off device, unplug all devices except Magsafe charger
2) Hold down left Shift, Control, Option, and Power button at the same time for ~5 sec (note you may see a change in the Magsafe LED color for a second)
3) Power machine on and see if device connects
Sometimes a glitch in the System Management Controller (yes, even on Windows machines) can cause a USB port to go dead. If it continues to not work, reach out to your IT dept./technician to see if perhaps there is a hardware failure.
Best Answer
In most cases yes you can.
But if the charger is too weak (less than 1 amps), it will charge your iPhone more slowly than the original charger.