Configure PHP application to use custom SMTP server

Hi,

We’re migrating sites into platform.sh and we currently use Sparkpost to send our emails. We have DKIM validation etc. configured there so want to keep sending via Sparkpost when we move to Platform.

I’ve read through:

But there doesn’t seem to be anything obvious on how to change the outbound email server that the default mail() PHP function would use, or similar.

Do I need to configure my application to connect to the Sparkpost SMTP server directly, or is there a way to set an environment variable or similar in Platform that will send the email from our applications via Sparkpost instead of the Sendgrid default configuration?

There isn’t a way to override the Platform.sh provided (Sendgrid-powered) SMTP service and variable at the PHP level that would affect the mail() function. We’d recommend you do that within your application instead, which is pretty straightforward with Drupal, Magento, WordPress, etc., or a bit more code replacement work with PHPMailer.

You could use environment variables to differentiate between production and non-production domains if you wanted to disable mailing or use a different SMTP host.

We also have some documentation on using SwiftMailer with Symfony as well.