0

I have a server with a static IP and also a domain pointing to it. Because it is behind a firewall that blocks SMTP (ingoing and outgoing), I am not able to send any EMail from it.

To be able to send and receive EMail with the domain anyways, I use Mailgun.

I can send EMail with GMail, for example - but not with PHP, since I have only found instructions to configure sendmail() using SMTP. Fortunately, Mailgun offers a HTTPS API to send EMail.

The question

How can I configure PHP to call a script on my server, which itself calls the Mailgun API?

Note: calling the API is not the issue. I only need help configuring PHP.

What I have tried

In the php.ini, you can set the path to the sendmail binary like this:

sendmail_path = /path/to/sendmail

I pointed this to a script which just dumps all params into a file:

echo "$@" > /path/to/output.txt

The script indeed gets called whenever mail() in PHP is called, but apparently there is a problem with the parameters. When I cat output.txt, I only get two empty lines.

paolo
  • 387
  • 3
  • 14
  • I have never used Mailgun. yet I feel its worth looking at PHPXmail/phpmailer as a different solution.. http://www.inmotionhosting.com/support/email/send-email-from-a-page/using-phpmailer-to-send-mail-through-php – Aravinda Jan 23 '16 at 17:10
  • Mailgun is actually a service provider that hosts the SMTP server for you. Using phpmailer is not a solution because it, too, relies on the SMTP port being open. – paolo Jan 23 '16 at 17:34

1 Answers1

0

I was able to solve the problem. It was simply that mail() feeds the headers and contents of the mail into the stdin of the respective sendmail binary/script.

So I adapted my script to read from stdin and that indeed worked.

Credit to this tutorial, which brought me on the right track.

paolo
  • 387
  • 3
  • 14