Implement placeholders

This commit is contained in:
Kumi 2020-09-03 11:14:13 +02:00
parent e456bedc68
commit 4d1c18c542
3 changed files with 24 additions and 2 deletions

File diff suppressed because one or more lines are too long

View file

@ -44,6 +44,17 @@ paths:
description: "Error message, only included if an error has occurred"
required: false
definitions:
Placeholder:
type: "object"
properties:
name:
type: "string"
required: true
description: "Name of the placeholder - will be converted to ALL CAPS by the server if it isn't already"
value:
type: "string"
required: false
description: "Value to insert into placeholder"
Attachment:
type: "object"
properties:
@ -107,6 +118,11 @@ definitions:
description: "Array of `Attachment` objects to be attached to the email"
items:
$ref: "#/definitions/Attachment"
placeholders:
type: "array"
description: "Array of `Placeholder` objects. Any occurrences of `{PLACEHOLDER_NAME}` (`name` in all caps enclosed with curly brackets) in the email's HTML or plain text will be replaced by `value`."
items:
$ref: "#/definitions/Placeholder"
key:
type: "string"
description: "API key to authenticate request with"

View file

@ -22,6 +22,11 @@ try {
$html = ($json["html"] ? $json["html"] : ($json["htmlurl"] ? file_get_contents($json["htmlurl"]) : null));
$text = ($json["text"] ? $json["text"] : ($json["texturl"] ? file_get_contents($json["texturl"]) : null));
foreach ($json["placeholders"] as $placeholder) {
$html = str_replace("{".strtoupper($placeholder["name"])."}", $placeholder["value"], $html);
$text = str_replace("{".strtoupper($placeholder["name"])."}", $placeholder["value"], $text);
}
$mailer->isSMTP();
$mailer->Host = $MAIL_HOST;
$mailer->SMTPAuth = (bool) $MAIL_USER;