Giter Site home page Giter Site logo

mailer-php-api's Introduction

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

$headers = [
    'Content-type: application/x-www-form-urlencoded',
    "Authorization: Bearer API_TOKEN_GOES_HERE",
];

$data = http_build_query([
    'to_email': '[email protected]',
    '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

const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    Authorization: 'Bearer API_TOKEN_GOES_HERE'
  },
  body: new URLSearchParams({
    to_email: '[email protected]',
    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

import http.client

conn = http.client.HTTPSConnection("example.com")

payload = "[email protected]&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"))

mailer-php-api's People

Contributors

dag0310 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.