rosavox/lib/alveolata/email/functions.php
2025-05-23 07:33:29 +00:00

75 lines
1.7 KiB
PHP

<?php
namespace alveolata\email;
require_once(DIR_ALVEOLATA . '/email/implementation-legacy/functions.php');
require_once(DIR_ALVEOLATA . '/email/implementation-pear/functions.php');
require_once(DIR_ALVEOLATA . '/email/implementation-swift/functions.php');
require_once(DIR_ALVEOLATA . '/email/implementation-phpmailer/functions.php');
/**
* @param array $credentials_raw {
* record<
* ?negotiation_type:string,
* host:string,
* ?port:integer,
* ?auth_type:string,
* username:string,
* password:string
* >
* }
* @param array $data {
* record<
* to:list<string>,
* subject:string,
* ?body_plain:string,
* ?body_html:string,
* ?from:string,
* ?cc:list<string>,
* ?bcc:list<string>,
* ?reply_to:string,
* ?attachments:list<record<path:string,mime:string,?name:string>>
* >
* }
* @throws Exception if mail can not be sent
* @author Christian Fraß <frass@greenscale.de>
*/
function send(
array $credentials_raw,
array $data_raw,
array $options = []
) : void
{
$options = \array_merge(
[
'implementation' => 'swift',
],
$options
);
$credentials = new struct_credentials($credentials_raw);
$data = new struct_data($data_raw);
switch ($options['implementation']) {
default:
case 'legacy': {
implementations\legacy\send($credentials, $data);
break;
}
case 'pear': {
implementations\pear\send($credentials, $data);
break;
}
case 'swift': {
implementations\swift\send($credentials, $data);
break;
}
case 'phpmailer': {
implementations\phpmailer\send($credentials, $data);
break;
}
}
}
?>