You can't travel in a car without a ticket that will identify you. The shipping companies in Spain charge both per traveller and car. You have to pay for your ticket and the car is added as a plus, depending on the availability.
I wouldn't recommend hitching in the car of a person you don't know. To me is the same risk as carrying somebody's else luggage at an airport, you don't know what is inside.
The companies that I know that operate the routes between Spain and Morocco are FRS, Transmediterránea and Balearia. You can get in this links all the information about the routes and prices. Don't forget to check promotions, even if they are charging you per car, an offer can lower the price of the travel