https://github.com/dag0310/mailer-php-api
Send emails using an HTTP PHP API using PHPMailer.
https://github.com/dag0310/mailer-php-api
api email http javascript mailing php phpmailer python
Last synced: about 1 month ago
JSON representation
Send emails using an HTTP PHP API using PHPMailer.
- Host: GitHub
- URL: https://github.com/dag0310/mailer-php-api
- Owner: dag0310
- License: lgpl-2.1
- Created: 2023-09-08T00:26:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-12-17T21:39:03.000Z (2 months ago)
- Last Synced: 2025-12-21T09:12:29.078Z (about 2 months ago)
- Topics: api, email, http, javascript, mailing, php, phpmailer, python
- Language: PHP
- Homepage:
- Size: 160 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mailer - PHP API
Send emails using an HTTP PHP API using PHPMailer.
## Installation
- Just copy the `www` folder to your webserver.
- Make sure to rename `config.template.ini` to `config.ini` and set the fields.
- Make sure `config.ini` is inaccessible through the web, .htaccess does this already for Apache servers.
## Usage examples
### PHP
```php
$headers = [
'Content-type: application/x-www-form-urlencoded',
"Authorization: Bearer API_TOKEN_GOES_HERE",
];
$data = http_build_query([
'to_email': 'john.doe@example.com',
'subject': 'Test email',
'message_html': 'HTML message body',
]);
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", $headers),
'content' => $data,
],
]);
$response = file_get_contents('https://example.com/mailer/', FALSE, $context);
if ($response === FALSE) {
die('Error: Unable to send the request.');
}
```
### JavaScript
```javascript
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Bearer API_TOKEN_GOES_HERE'
},
body: new URLSearchParams({
to_email: 'john.doe@example.com',
subject: 'Test email',
message_html: 'HTML message body',
})
};
fetch('https://example.com/mailer/', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
```
### Python
```python
import http.client
conn = http.client.HTTPSConnection("example.com")
payload = "to_email=john.doe@example.com&subject=Test%20email&message_html=HTML%20message%20body"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Authorization': "Bearer API_TOKEN_GOES_HERE"
}
conn.request("POST", "/mailer/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```