I have a problem sending multiple mails over uniform at the same time. Both emailAction work for themselves. But if I want to use both, then only html-newsletter-mail
will be sent, no matter which order.
$form->emailAction([
'to' => 'debug@...de',
'from' => $from,
'subject' => '[' . $site->title() . '] Bierclub-Anmeldung',
'service' => 'html-mail',
'snippet' => 'forms/email-template'
]);
$form->emailAction([
'to' => $form->data('email'),
'from' => $from,
'subject' => '[' . $site->title() . '] Newsletter Anmeldung',
'service' => 'html-newsletter-mail',
'snippet' => 'ka-newsletter-email',
]);
email::$services['html-mail'] = function ($email) {
$headers = array(
'From: ' . $email->from,
'Reply-To: ' . $email->replyTo,
'Return-Path: ' . $email->replyTo,
'Bcc: debug@.....de',
'Message-ID: <' . time() . '-' . $email->from . '>',
'X-Mailer: PHP v' . phpversion(),
'Content-Type: text/html; charset=utf-8',
'Content-Transfer-Encoding: 8bit',
);
if (!empty($email->options['cc'])) {
$headers[] = 'CC: ' . $email->options['cc'];
}
ini_set('sendmail_from', $email->from);
$send = mail($email->to, str::utf8($email->subject), str::utf8($email->body), implode(PHP_EOL, $headers));
ini_restore('sendmail_from');
if (!$send) {
throw new Error('The email could not be sent');
}
};
email::$services['html-newsletter-mail'] = function ($email) {
$to = c::get('ka.newsletter.mail.to', false);
$from = c::get('ka.newsletter.mail.from', false);
$key = c::get('ka.newsletter.crypt.key', false);
if ($to !== false && $from !== false && $key !== false) {
$bcc = c::get('ka.newsletter.mail.bcc', false);
$headers = array(
'From: ' . $email->from,
'Reply-To: ' . $to,
'Message-ID: <' . time() . '-' . $email->from . '>',
'X-Mailer: PHP v' . phpversion(),
// changed:
'Content-Type: text/html; charset=utf-8',
'Content-Transfer-Encoding: 8bit',
);
if ($bcc !== false) {
$headers[] = 'Bcc: ' . $bcc;
}
ini_set('sendmail_from', $email->from);
$send = mail($email->to, str::utf8($email->subject), str::utf8($email->body), implode(PHP_EOL, $headers));
ini_restore('sendmail_from');
if (!$send) {
throw new Error('The email could not be sent');
}
}
};