Upgrade to Kirby 3.3.2

This commit is contained in:
Bastian Allgeier
2019-12-17 10:31:21 +01:00
parent 3a82406bed
commit 91919964db
20 changed files with 361 additions and 181 deletions

View File

@@ -25,7 +25,9 @@ class Email
protected $bcc;
protected $cc;
protected $from;
protected $fromName;
protected $replyTo;
protected $replyToName;
protected $isSent = false;
protected $subject;
protected $to;
@@ -75,6 +77,11 @@ class Email
return $this->from;
}
public function fromName(): ?string
{
return $this->fromName;
}
public function isHtml()
{
return $this->body()->html() !== null;
@@ -90,6 +97,11 @@ class Email
return $this->replyTo;
}
public function replyToName(): ?string
{
return $this->replyToName;
}
protected function resolveEmail($email = null, bool $multiple = true)
{
if ($email === null) {
@@ -97,16 +109,27 @@ class Email
}
if (is_array($email) === false) {
$email = [$email];
$email = [$email => null];
}
foreach ($email as $address) {
$result = [];
foreach ($email as $address => $name) {
// convert simple email arrays to associative arrays
if (is_int($address) === true) {
// the value is the address, there is no name
$address = $name;
$result[$address] = null;
} else {
$result[$address] = $name;
}
// ensure that the address is valid
if (V::email($address) === false) {
throw new Exception(sprintf('"%s" is not a valid email address', $address));
}
}
return $multiple === true ? $email : $email[0];
return $multiple === true ? $result : array_keys($result)[0];
}
public function send(): bool
@@ -148,12 +171,24 @@ class Email
return $this;
}
protected function setFromName(string $fromName = null)
{
$this->fromName = $fromName;
return $this;
}
protected function setReplyTo(string $replyTo = null)
{
$this->replyTo = $this->resolveEmail($replyTo, false);
return $this;
}
protected function setReplyToName(string $replyToName = null)
{
$this->replyToName = $replyToName;
return $this;
}
protected function setSubject(string $subject)
{
$this->subject = $subject;

View File

@@ -21,22 +21,22 @@ class PHPMailer extends Email
$mailer = new Mailer(true);
// set sender's address
$mailer->setFrom($this->from());
$mailer->setFrom($this->from(), $this->fromName() ?? '');
// optional reply-to address
if ($replyTo = $this->replyTo()) {
$mailer->addReplyTo($replyTo);
$mailer->addReplyTo($replyTo, $this->replyToName() ?? '');
}
// add (multiple) recepient, CC & BCC addresses
foreach ($this->to() as $to) {
$mailer->addAddress($to);
foreach ($this->to() as $email => $name) {
$mailer->addAddress($email, $name ?? '');
}
foreach ($this->cc() as $cc) {
$mailer->addCC($cc);
foreach ($this->cc() as $email => $name) {
$mailer->addCC($email, $name ?? '');
}
foreach ($this->bcc() as $bcc) {
$mailer->addBCC($bcc);
foreach ($this->bcc() as $email => $name) {
$mailer->addBCC($email, $name ?? '');
}
$mailer->Subject = $this->subject();