We now have three domain names located on a single devoted server each using its own devoted IP.

Domain A - Has got the server primary Ip (default server IP)
Domain B - Features its own Ip
Domain C - features its own Ip

If the email is out from Domain B it uses the Domain A Ip in outgoing which makes emails from Domain B using PHP go right to junk e-mail box of Gmail etc.

Can there be in whatever way to alter the origin IP based on in which the email arises from in PHP? What should we switch to fix this?

This really is nothing related to PHP.

No you cannot spoof addresses in the manner you suggest - but why emails are now being classified as junk e-mail happens because you've only got Host A released inside your SPF. Just add others towards the allowed senders list:

"v=spf1 a:hostA.example.com a:hostB.example.com a:hostC.example.com"

C.

You are not giving any particulars regarding your server setup which means this can't be clarified. PHP can, however, make use of a SMTP server of your choosing. The simplest method to set this up is really a tool like PHPMailer.

If you cannot alter the IP you are delivering from, you have to change domain B's MX record making Domain A (or its IP) the mail server for your domain. I am confident junk e-mail filters like Google mail search for the MX record only. Obviously, you would need to have both E-Mail delivering and receiving facilities on Domain A with this to operate.

PHP is generally established to drop mail to the localhost MTA, that will always send it on from the own bound Ip. So, no.

To prevent being marked as junk e-mail since your mail originates from a previous address that does not connect using the DNS records (MX or fallback A) for any domain, add an SPF record towards the DNS for the domain names stating that mail in the delivering Ip is okay.