Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.58 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.58 KB

php-restmailer

🐘 Simple PHP script that implements a RESTful API to send e-mails.

Inspired by andrisro/REST-PHP-Mailer.

Tested with PHP 8.0.8.

Usage

Before uploading the script to your web server document directory, you may want to customize the configuration section. In particular, you should definitely change the authentication credentials and use a strong password.

Then you can use it like in the following examples:

curl 'https://admin:changeme@my-host.example.com/restmailer.php?to=my-recipient@example.com&subject=test-get&message=This%20is%20my%20GET%20test.'
curl -XPOST 'https://admin:changeme@my-host.example.com/restmailer.php' \
    -d 'to=my-recipient@example.com&subject=test-post&message=This%20is%20my%20POST%20test.'
ls | curl --data-binary @- 'https://admin:changeme@my-host.example.com/restmailer.php?to=my-recipient@example.com&subject=test-body'
curl -XPOST 'https://admin:changeme@my-host.example.com/restmailer.php' \
    -H 'Content-Type: application/json' \
    -d '{
        "to": "my-recipient@example.com",
        "subject": "test-json",
        "message": "This is my JSON test.",
        "additional_headers": {"Reply-To": "another-address@example.com"}
    }'

Known issues

As stated here, if you are running PHP under CGI/FastCGI Apache, you should add this line to your .htaccess file to make authentication work:

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0