Prima, danke! Wieder einen Step weiter. Mein Script sieht nun so aus:
PHP-Code:
<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');
class RapidmailClass extends Backend {
public function myProcessFormData($arrPost, $arrForm, $arrFiles)
{
if($arrForm['formID'] == 'vorteil-test') {
if ($arrPost['newsletter'] == 'ja') {
use Camspiers\JsonPretty\JsonPretty;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
require_once __DIR__ . '/../../../vendor/autoload.php';
$recipientlistId = 'XXXX';
$username = 'XXXX';
$password = 'XXXX';
$client = new Client([
// Base URI for all guzzle requests, remember that the emailsys API only supports HTTPS
'base_uri' => 'https://apiv3.emailsys.net'
]);
// A simple utility to prettify json data
$pretty = new JsonPretty();
try {
$response = $client->post('/recipients', [
// Guzzle request headers API is documented here: http://guzzle.readthedocs.io/en/stable/request-options.html#headers
'headers' => [
// The accept header tells the API that you expect JSON to be returned
'Accept' => 'application/json'
],
// Guzzle request authentication is documented here: http://guzzle.readthedocs.io/en/stable/request-options.html#auth
'auth' => [
$username,
$password
],
// Guzzle JSON request API is documented here: http://guzzle.readthedocs.io/en/stable/quickstart.html#uploading-data
'json' => [
'email' => 'test@example.com',
'recipientlist_id' => $recipientlistId
]
]);
echo $pretty->prettify((string)$response->getBody()) . PHP_EOL;
} catch (ClientException $e) {
// Guzzle exception handling is documented here: http://guzzle.readthedocs.io/en/stable/quickstart.html#exceptions
// ClientException is thrown for any 4XX HTTP statuscode (client errors)
if ($e->hasResponse()) {
echo $pretty->prettify((string)$e->getResponse()->getBody()) . PHP_EOL;
}
}
}
}
}
}
Binde ich es so ein, wirft die Seite beim Absenden eines Formulars jedoch folgenden Fehler aus:
Code:
[2019-09-25 08:21:20] request.INFO: Matched route "contao_frontend". {"route":"contao_frontend","route_parameters":{"_token_check":true,"_controller":"Contao\\CoreBundle\\Controller\\FrontendController::indexAction","_scope":"frontend","alias":"formular-vorteilsangebote","_route":"contao_frontend"},"request_uri":"//formular-vorteilsangebote?angebot=Viking","method":"POST"} []
[2019-09-25 08:21:20] security.INFO: Attempting SimplePreAuthentication. {"key":"frontend","authenticator":"Contao\\CoreBundle\\Security\\ContaoAuthenticator"} []
[2019-09-25 08:21:22] app.CRITICAL: An exception occurred. {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ClassNotFoundException(code: 0): Attempted to load class \"RapidmailClass\" from the global namespace.\nDid you forget a \"use\" statement? at //vendor/contao/core-bundle/src/Resources/contao/library/Contao/System.php:171)"} []