We need to send email using PHP's mail() function (Actually CakePHP, which wraps that function) directly from our dedicated server (app.ourserver.com). We would like to send mail from app.ourserver.com, but need to send it as mail.domain1.com AND mail.domain2.com. We don't want to use STMP as it's slow to connect, especially to our external mail servers (mail.domain1.com AND mail.domain2.com). I've tried to add proper SPF records to the two domains domain1.com and domain2.com, to allow ourserver.com to send out email, but the email gets immediately discarded as SPAM on the receiving end. How would we go about doing this, without using authenticated SMTP accounts on our external domains?
I think your title is incorrect. Should it be "How do I send eMail from another Domain?" or something like that.
There are any number of reasons you get classified as spam:
- rDNS validation doesn't work for IP address (PTR -> A -> PTR).
- rDNS validation doesn't work for the name you use in the HELO or EHLO command.
- Nothing is answering on port 25 on your server. You may need to set up a local mail server, not that I would recommend you do so.
- You are blacklisted (check your IP and domain).
- SPF is failing.
- DMARC is failing.
If you look at the headers of a message classified as spam, there may well be headers telling you why it was classified as spam.
Your first choice should be to use a relay server which is permitted to send mail for your domain. Connecting to the submission port (which may require authentication) should be quite fast. The fact that you find connecting to the domain's mail servers very slow may indicate that your are triggeting spam avoidance rules there. (My rules provide slow service to poorly configured hosts and express service to well configured hosts. This drops lots of spam.)
You can set up SSMTP, a lightweight program that replaces postfix and is good for just sending email out - but it doesn't receive email. You can set the from address. It works well for me. Setup is slightly fiddly so you'll need to find a guide or tutorial - mine won't be out for a week or so.