Upgrade to 3.4.4
This commit is contained in:
@@ -19,30 +19,64 @@ class Body
|
||||
{
|
||||
use Properties;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $html;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* Email body constructor
|
||||
*
|
||||
* @param array $props
|
||||
*/
|
||||
public function __construct(array $props = [])
|
||||
{
|
||||
$this->setProperties($props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML content of the email body
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plain text content of the email body
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function text()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTML content for the email body
|
||||
*
|
||||
* @param string|null $html
|
||||
* @return self
|
||||
*/
|
||||
protected function setHtml(string $html = null)
|
||||
{
|
||||
$this->html = $html;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plain text content for the email body
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return self
|
||||
*/
|
||||
protected function setText(string $text = null)
|
||||
{
|
||||
$this->text = $text;
|
||||
|
@@ -21,57 +21,142 @@ class Email
|
||||
{
|
||||
use Properties;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var \Kirby\Email\Body|null
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $bcc;
|
||||
|
||||
/**
|
||||
* @var \Closure|null
|
||||
*/
|
||||
protected $beforeSend;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $cc;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $fromName;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $replyTo;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $replyToName;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isSent = false;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $transport;
|
||||
|
||||
/**
|
||||
* Email constructor
|
||||
*
|
||||
* @param array $props
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct(array $props = [], bool $debug = false)
|
||||
{
|
||||
$this->setProperties($props);
|
||||
|
||||
if ($debug === false) {
|
||||
$this->send();
|
||||
$this->send(); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the email attachments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Kirby\Email\Body
|
||||
* Returns the email body
|
||||
*
|
||||
* @return \Kirby\Email\Body|null
|
||||
*/
|
||||
public function body()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "bcc" recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function bcc(): array
|
||||
{
|
||||
return $this->bcc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the beforeSend callback closure,
|
||||
* which has access to the PHPMailer instance
|
||||
*
|
||||
* @return \Closure|null
|
||||
*/
|
||||
public function beforeSend(): ?Closure
|
||||
{
|
||||
return $this->beforeSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "cc" recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cc(): array
|
||||
{
|
||||
return $this->cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default transport settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaultTransport(): array
|
||||
{
|
||||
return [
|
||||
@@ -79,36 +164,74 @@ class Email
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "from" email address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function from(): string
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "from" name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function fromName(): ?string
|
||||
{
|
||||
return $this->fromName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the email has an HTML body
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHtml()
|
||||
{
|
||||
return $this->body()->html() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the email has been sent successfully
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSent(): bool
|
||||
{
|
||||
return $this->isSent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "reply to" email address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function replyTo(): string
|
||||
{
|
||||
return $this->replyTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "reply to" name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function replyToName(): ?string
|
||||
{
|
||||
return $this->replyToName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts single or multiple email addresses to a sanitized format
|
||||
*
|
||||
* @param string|array|null $email
|
||||
* @param bool $multiple
|
||||
* @return array|mixed|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function resolveEmail($email = null, bool $multiple = true)
|
||||
{
|
||||
if ($email === null) {
|
||||
@@ -139,17 +262,34 @@ class Email
|
||||
return $multiple === true ? $result : array_keys($result)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send(): bool
|
||||
{
|
||||
return $this->isSent = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the email attachments
|
||||
*
|
||||
* @param array|null $attachments
|
||||
* @return self
|
||||
*/
|
||||
protected function setAttachments($attachments = null)
|
||||
{
|
||||
$this->attachments = $attachments ?? [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the email body
|
||||
*
|
||||
* @param string|array $body
|
||||
* @return self
|
||||
*/
|
||||
protected function setBody($body)
|
||||
{
|
||||
if (is_string($body) === true) {
|
||||
@@ -160,76 +300,151 @@ class Email
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets "bcc" recipients
|
||||
*
|
||||
* @param string|array|null $bcc
|
||||
* @return $this
|
||||
*/
|
||||
protected function setBcc($bcc = null)
|
||||
{
|
||||
$this->bcc = $this->resolveEmail($bcc);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "beforeSend" callback
|
||||
*
|
||||
* @param \Closure|null $beforeSend
|
||||
* @return self
|
||||
*/
|
||||
protected function setBeforeSend(?Closure $beforeSend = null)
|
||||
{
|
||||
$this->beforeSend = $beforeSend;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets "cc" recipients
|
||||
*
|
||||
* @param string|array|null $cc
|
||||
* @return self
|
||||
*/
|
||||
protected function setCc($cc = null)
|
||||
{
|
||||
$this->cc = $this->resolveEmail($cc);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "from" email address
|
||||
*
|
||||
* @param string $from
|
||||
* @return self
|
||||
*/
|
||||
protected function setFrom(string $from)
|
||||
{
|
||||
$this->from = $this->resolveEmail($from, false);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "from" name
|
||||
*
|
||||
* @param string|null $fromName
|
||||
* @return self
|
||||
*/
|
||||
protected function setFromName(string $fromName = null)
|
||||
{
|
||||
$this->fromName = $fromName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "reply to" email address
|
||||
*
|
||||
* @param string|null $replyTo
|
||||
* @return self
|
||||
*/
|
||||
protected function setReplyTo(string $replyTo = null)
|
||||
{
|
||||
$this->replyTo = $this->resolveEmail($replyTo, false);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "reply to" name
|
||||
*
|
||||
* @param string|null $replyToName
|
||||
* @return self
|
||||
*/
|
||||
protected function setReplyToName(string $replyToName = null)
|
||||
{
|
||||
$this->replyToName = $replyToName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the email subject
|
||||
*
|
||||
* @param string $subject
|
||||
* @return self
|
||||
*/
|
||||
protected function setSubject(string $subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recipients of the email
|
||||
*
|
||||
* @param string|array $to
|
||||
* @return self
|
||||
*/
|
||||
protected function setTo($to)
|
||||
{
|
||||
$this->to = $this->resolveEmail($to);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the email transport settings
|
||||
*
|
||||
* @param array|null $transport
|
||||
* @return self
|
||||
*/
|
||||
protected function setTransport($transport = null)
|
||||
{
|
||||
$this->transport = $transport;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the email subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function subject(): string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the email recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to(): array
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the email transports settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transport(): array
|
||||
{
|
||||
return $this->transport ?? $this->defaultTransport();
|
||||
|
@@ -17,6 +17,13 @@ use PHPMailer\PHPMailer\PHPMailer as Mailer;
|
||||
*/
|
||||
class PHPMailer extends Email
|
||||
{
|
||||
/**
|
||||
* Sends email via PHPMailer library
|
||||
*
|
||||
* @param bool $debug
|
||||
* @return bool
|
||||
* @throws \Kirby\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function send(bool $debug = false): bool
|
||||
{
|
||||
$mailer = new Mailer(true);
|
||||
@@ -83,6 +90,6 @@ class PHPMailer extends Email
|
||||
return $this->isSent = true;
|
||||
}
|
||||
|
||||
return $this->isSent = $mailer->send();
|
||||
return $this->isSent = $mailer->send(); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user