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 Icat output.txt
, I only get two empty lines.
Answer
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.
Attribution
Source : Link , Question Author : paolo , Answer Author : paolo