2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Control\Email;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Control\HTTP;
|
2017-01-13 02:48:46 +01:00
|
|
|
use SilverStripe\Core\Convert;
|
2017-10-16 05:43:12 +02:00
|
|
|
use SilverStripe\Core\Environment;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2017-01-13 02:48:46 +01:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
2017-10-18 05:09:14 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\View\Requirements;
|
2017-10-18 05:09:14 +02:00
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
use SilverStripe\View\ThemeResourceLoader;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\View\ViewableData;
|
2017-01-13 02:48:46 +01:00
|
|
|
use Swift_Message;
|
|
|
|
use Swift_MimePart;
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Class to support sending emails.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class Email extends ViewableData
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array
|
|
|
|
* @config
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private static $send_all_emails_to = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array
|
|
|
|
* @config
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private static $cc_all_emails_to = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array
|
|
|
|
* @config
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private static $bcc_all_emails_to = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array
|
|
|
|
* @config
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private static $send_all_emails_from = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* This will be set in the config on a site-by-site basis
|
2019-10-03 00:31:43 +02:00
|
|
|
* @see https://docs.silverstripe.org/en/4/developer_guides/email/#administrator-emails
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @config
|
2019-10-03 00:31:43 +02:00
|
|
|
* @var string|array The default administrator email address or array of [email => name]
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private static $admin_email = null;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var Swift_Message
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private $swiftMessage;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var string The name of the HTML template to render the email with (without *.ss extension)
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-10-18 05:09:14 +02:00
|
|
|
private $HTMLTemplate = null;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var string The name of the plain text template to render the plain part of the email with
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-10-18 05:09:14 +02:00
|
|
|
private $plainTemplate = null;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var Swift_MimePart
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private $plainPart;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array|ViewableData Additional data available in a template.
|
2016-11-29 00:31:16 +01:00
|
|
|
* Used in the same way than {@link ViewableData->customize()}.
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private $data = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @var array
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
private $failedRecipients = array();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Checks for RFC822-valid email format.
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $address
|
|
|
|
* @return boolean
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @copyright Cal Henderson <cal@iamcal.com>
|
|
|
|
* This code is licensed under a Creative Commons Attribution-ShareAlike 2.5 License
|
|
|
|
* http://creativecommons.org/licenses/by-sa/2.5/
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public static function is_valid_address($address)
|
|
|
|
{
|
|
|
|
return \Swift_Validate::email($address);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
/**
|
|
|
|
* Get send_all_emails_to
|
|
|
|
*
|
|
|
|
* @return array Keys are addresses, values are names
|
|
|
|
*/
|
|
|
|
public static function getSendAllEmailsTo()
|
|
|
|
{
|
|
|
|
return static::mergeConfiguredEmails('send_all_emails_to', 'SS_SEND_ALL_EMAILS_TO');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get cc_all_emails_to
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getCCAllEmailsTo()
|
|
|
|
{
|
|
|
|
return static::mergeConfiguredEmails('cc_all_emails_to', 'SS_CC_ALL_EMAILS_TO');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get bcc_all_emails_to
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getBCCAllEmailsTo()
|
|
|
|
{
|
|
|
|
return static::mergeConfiguredEmails('bcc_all_emails_to', 'SS_BCC_ALL_EMAILS_TO');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get send_all_emails_from
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getSendAllEmailsFrom()
|
|
|
|
{
|
|
|
|
return static::mergeConfiguredEmails('send_all_emails_from', 'SS_SEND_ALL_EMAILS_FROM');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Normalise email list from config merged with env vars
|
|
|
|
*
|
|
|
|
* @param string $config Config key
|
|
|
|
* @param string $env Env variable key
|
|
|
|
* @return array Array of email addresses
|
|
|
|
*/
|
|
|
|
protected static function mergeConfiguredEmails($config, $env)
|
|
|
|
{
|
|
|
|
// Normalise config list
|
|
|
|
$normalised = [];
|
|
|
|
$source = (array)static::config()->get($config);
|
|
|
|
foreach ($source as $address => $name) {
|
|
|
|
if ($address && !is_numeric($address)) {
|
|
|
|
$normalised[$address] = $name;
|
|
|
|
} elseif ($name) {
|
|
|
|
$normalised[$name] = null;
|
|
|
|
}
|
|
|
|
}
|
2017-10-16 05:43:12 +02:00
|
|
|
$extra = Environment::getEnv($env);
|
2017-06-22 12:50:45 +02:00
|
|
|
if ($extra) {
|
|
|
|
$normalised[$extra] = null;
|
|
|
|
}
|
|
|
|
return $normalised;
|
|
|
|
}
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Encode an email-address to protect it from spambots.
|
|
|
|
* At the moment only simple string substitutions,
|
|
|
|
* which are not 100% safe from email harvesting.
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $email Email-address
|
|
|
|
* @param string $method Method for obfuscating/encoding the address
|
|
|
|
* - 'direction': Reverse the text and then use CSS to put the text direction back to normal
|
|
|
|
* - 'visible': Simple string substitution ('@' to '[at]', '.' to '[dot], '-' to [dash])
|
|
|
|
* - 'hex': Hexadecimal URL-Encoding - useful for mailto: links
|
|
|
|
* @return string
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public static function obfuscate($email, $method = 'visible')
|
|
|
|
{
|
|
|
|
switch ($method) {
|
2017-02-22 04:14:53 +01:00
|
|
|
case 'direction':
|
2017-01-13 02:48:46 +01:00
|
|
|
Requirements::customCSS('span.codedirection { unicode-bidi: bidi-override; direction: rtl; }', 'codedirectionCSS');
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return '<span class="codedirection">' . strrev($email) . '</span>';
|
2017-02-22 04:14:53 +01:00
|
|
|
case 'visible':
|
2017-01-13 02:48:46 +01:00
|
|
|
$obfuscated = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] ');
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return strtr($email, $obfuscated);
|
2017-02-22 04:14:53 +01:00
|
|
|
case 'hex':
|
2017-01-13 02:48:46 +01:00
|
|
|
$encoded = '';
|
2019-07-24 12:17:49 +02:00
|
|
|
$emailLength = strlen($email);
|
|
|
|
for ($x = 0; $x < $emailLength; $x++) {
|
|
|
|
$encoded .= '&#x' . bin2hex($email[$x]) . ';';
|
2017-01-13 02:48:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $encoded;
|
|
|
|
default:
|
|
|
|
user_error('Email::obfuscate(): Unknown obfuscation method', E_USER_NOTICE);
|
|
|
|
|
|
|
|
return $email;
|
|
|
|
}
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Email constructor.
|
|
|
|
* @param string|array|null $from
|
|
|
|
* @param string|array|null $to
|
2016-11-29 00:31:16 +01:00
|
|
|
* @param string|null $subject
|
|
|
|
* @param string|null $body
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array|null $cc
|
|
|
|
* @param string|array|null $bcc
|
|
|
|
* @param string|null $returnPath
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$from = null,
|
|
|
|
$to = null,
|
|
|
|
$subject = null,
|
|
|
|
$body = null,
|
|
|
|
$cc = null,
|
2017-01-13 02:48:46 +01:00
|
|
|
$bcc = null,
|
|
|
|
$returnPath = null
|
2016-11-29 00:31:16 +01:00
|
|
|
) {
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($from) {
|
|
|
|
$this->setFrom($from);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($to) {
|
|
|
|
$this->setTo($to);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($subject) {
|
|
|
|
$this->setSubject($subject);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($body) {
|
|
|
|
$this->setBody($body);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($cc) {
|
|
|
|
$this->setCC($cc);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($bcc) {
|
|
|
|
$this->setBCC($bcc);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($returnPath) {
|
|
|
|
$this->setReturnPath($returnPath);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return Swift_Message
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getSwiftMessage()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
if (!$this->swiftMessage) {
|
|
|
|
$this->setSwiftMessage(new Swift_Message(null, null, 'text/html', 'utf-8'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->swiftMessage;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param Swift_Message $swiftMessage
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setSwiftMessage($swiftMessage)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-26 05:20:08 +01:00
|
|
|
$swiftMessage->setDate(DBDatetime::now()->getTimestamp());
|
2017-06-22 12:50:45 +02:00
|
|
|
if (!$swiftMessage->getFrom() && ($defaultFrom = $this->config()->get('admin_email'))) {
|
2017-01-13 02:48:46 +01:00
|
|
|
$swiftMessage->setFrom($defaultFrom);
|
|
|
|
}
|
|
|
|
$this->swiftMessage = $swiftMessage;
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getFrom()
|
|
|
|
{
|
|
|
|
return $this->getSwiftMessage()->getFrom();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setFrom($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setFrom($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addFrom($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addFrom($address, $name);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-22 12:50:45 +02:00
|
|
|
* @return string
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getSender()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->getSwiftMessage()->getSender();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $address
|
|
|
|
* @param string|null $name
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setSender($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setSender($address, $name);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return string
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getReturnPath()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->getSwiftMessage()->getReturnPath();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* The bounce handler address
|
|
|
|
*
|
|
|
|
* @param string $address Email address where bounce notifications should be sent
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setReturnPath($address)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setReturnPath($address);
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return array
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getTo()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->getSwiftMessage()->getTo();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Set recipient(s) of the email
|
|
|
|
*
|
|
|
|
* To send to many, pass an array:
|
|
|
|
* array('me@example.com' => 'My Name', 'other@example.com');
|
|
|
|
*
|
|
|
|
* @param string|array $address The message recipient(s) - if sending to multiple, use an array of address => name
|
|
|
|
* @param string|null $name The name of the recipient (if one)
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setTo($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setTo($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addTo($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addTo($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getCC()
|
|
|
|
{
|
|
|
|
return $this->getSwiftMessage()->getCc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setCC($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setCc($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addCC($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addCc($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBCC()
|
|
|
|
{
|
|
|
|
return $this->getSwiftMessage()->getBcc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setBCC($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setBcc($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addBCC($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addBcc($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getReplyTo()
|
|
|
|
{
|
|
|
|
return $this->getSwiftMessage()->getReplyTo();
|
|
|
|
}
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setReplyTo($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setReplyTo($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string|array $address
|
|
|
|
* @param string|null $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addReplyTo($address, $name = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addReplyTo($address, $name);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getSubject()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->getSwiftMessage()->getSubject();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $subject The Subject line for the email
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setSubject($subject)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setSubject($subject);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPriority()
|
|
|
|
{
|
|
|
|
return $this->getSwiftMessage()->getPriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $priority
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setPriority($priority)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setPriority($priority);
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $path Path to file
|
|
|
|
* @param string $alias An override for the name of the file
|
|
|
|
* @param string $mime The mime type for the attachment
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addAttachment($path, $alias = null, $mime = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$attachment = \Swift_Attachment::fromPath($path);
|
|
|
|
if ($alias) {
|
|
|
|
$attachment->setFilename($alias);
|
|
|
|
}
|
|
|
|
if ($mime) {
|
|
|
|
$attachment->setContentType($mime);
|
|
|
|
}
|
|
|
|
$this->getSwiftMessage()->attach($attachment);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $data
|
|
|
|
* @param string $name
|
|
|
|
* @param string $mime
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function addAttachmentFromData($data, $name, $mime = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$attachment = new \Swift_Attachment($data, $name);
|
|
|
|
if ($mime) {
|
|
|
|
$attachment->setContentType($mime);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->attach($attachment);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return array|ViewableData The template data
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getData()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->data;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param array|ViewableData $data The template data to set
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setData($data)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->data = $data;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array $name The data name to add or array to names => value
|
|
|
|
* @param string|null $value The value of the data to add
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function addData($name, $value = null)
|
|
|
|
{
|
|
|
|
if (is_array($name)) {
|
|
|
|
$this->data = array_merge($this->data, $name);
|
|
|
|
} elseif (is_array($this->data)) {
|
|
|
|
$this->data[$name] = $value;
|
2016-11-29 00:31:16 +01:00
|
|
|
} else {
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->data->$name = $value;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Remove a datum from the message
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param string $name
|
2016-11-29 00:31:16 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function removeData($name)
|
|
|
|
{
|
|
|
|
if (is_array($this->data)) {
|
|
|
|
unset($this->data[$name]);
|
|
|
|
} else {
|
|
|
|
$this->data->$name = null;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return string
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function getBody()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this->getSwiftMessage()->getBody();
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @param string $body The email body
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setBody($body)
|
|
|
|
{
|
2017-11-08 16:32:51 +01:00
|
|
|
$plainPart = $this->findPlainPart();
|
|
|
|
if ($plainPart) {
|
|
|
|
$this->getSwiftMessage()->detach($plainPart);
|
|
|
|
}
|
|
|
|
unset($plainPart);
|
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
$body = HTTP::absoluteURLs($body);
|
|
|
|
$this->getSwiftMessage()->setBody($body);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @return string The base URL for the email
|
|
|
|
*/
|
|
|
|
public function BaseURL()
|
|
|
|
{
|
|
|
|
return Director::absoluteBaseURL();
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Debugging help
|
|
|
|
*
|
|
|
|
* @return string Debug info
|
|
|
|
*/
|
|
|
|
public function debug()
|
|
|
|
{
|
|
|
|
$this->render();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-05-17 07:40:13 +02:00
|
|
|
$class = static::class;
|
|
|
|
return "<h2>Email template {$class}:</h2>\n" . '<pre>' . $this->getSwiftMessage()->toString() . '</pre>';
|
2017-01-13 02:48:46 +01:00
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHTMLTemplate()
|
|
|
|
{
|
2017-10-18 05:09:14 +02:00
|
|
|
if ($this->HTMLTemplate) {
|
|
|
|
return $this->HTMLTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ThemeResourceLoader::inst()->findTemplate(
|
|
|
|
SSViewer::get_templates_by_class(static::class, '', self::class),
|
|
|
|
SSViewer::get_themes()
|
|
|
|
);
|
2017-01-13 02:48:46 +01:00
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Set the template to render the email with
|
|
|
|
*
|
|
|
|
* @param string $template
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setHTMLTemplate($template)
|
|
|
|
{
|
|
|
|
if (substr($template, -3) == '.ss') {
|
|
|
|
$template = substr($template, 0, -3);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->HTMLTemplate = $template;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Get the template to render the plain part with
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPlainTemplate()
|
|
|
|
{
|
|
|
|
return $this->plainTemplate;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Set the template to render the plain part with
|
|
|
|
*
|
|
|
|
* @param string $template
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setPlainTemplate($template)
|
|
|
|
{
|
|
|
|
if (substr($template, -3) == '.ss') {
|
|
|
|
$template = substr($template, 0, -3);
|
|
|
|
}
|
|
|
|
$this->plainTemplate = $template;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* @param array $recipients
|
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function setFailedRecipients($recipients)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->failedRecipients = $recipients;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFailedRecipients()
|
|
|
|
{
|
|
|
|
return $this->failedRecipients;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Used by {@link SSViewer} templates to detect if we're rendering an email template rather than a page template
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function IsEmail()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Send the message to the recipients
|
|
|
|
*
|
|
|
|
* @return bool true if successful or array of failed recipients
|
|
|
|
*/
|
|
|
|
public function send()
|
|
|
|
{
|
|
|
|
if (!$this->getBody()) {
|
|
|
|
$this->render();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
if (!$this->hasPlainPart()) {
|
|
|
|
$this->generatePlainPartFromBody();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
return Injector::inst()->get(Mailer::class)->send($this);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @return array|bool
|
|
|
|
*/
|
|
|
|
public function sendPlain()
|
|
|
|
{
|
|
|
|
if (!$this->hasPlainPart()) {
|
|
|
|
$this->render(true);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-01-13 02:48:46 +01:00
|
|
|
return Injector::inst()->get(Mailer::class)->send($this);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* Render the email
|
|
|
|
* @param bool $plainOnly Only render the message as plain text
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function render($plainOnly = false)
|
|
|
|
{
|
|
|
|
if ($existingPlainPart = $this->findPlainPart()) {
|
|
|
|
$this->getSwiftMessage()->detach($existingPlainPart);
|
|
|
|
}
|
|
|
|
unset($existingPlainPart);
|
2017-10-18 05:09:14 +02:00
|
|
|
|
|
|
|
// Respect explicitly set body
|
|
|
|
$htmlPart = $plainOnly ? null : $this->getBody();
|
|
|
|
$plainPart = $plainOnly ? $this->getBody() : null;
|
|
|
|
|
|
|
|
// Ensure we can at least render something
|
|
|
|
$htmlTemplate = $this->getHTMLTemplate();
|
|
|
|
$plainTemplate = $this->getPlainTemplate();
|
|
|
|
if (!$htmlTemplate && !$plainTemplate && !$plainPart && !$htmlPart) {
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2018-08-14 17:26:31 +02:00
|
|
|
// Do not interfere with emails styles
|
|
|
|
Requirements::clear();
|
2019-06-14 12:39:47 +02:00
|
|
|
|
2017-10-18 05:09:14 +02:00
|
|
|
// Render plain part
|
|
|
|
if ($plainTemplate && !$plainPart) {
|
2019-06-14 12:39:47 +02:00
|
|
|
$plainPart = $this->renderWith($plainTemplate, $this->getData())->Plain();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 05:09:14 +02:00
|
|
|
// Render HTML part, either if sending html email, or a plain part is lacking
|
|
|
|
if (!$htmlPart && $htmlTemplate && (!$plainOnly || empty($plainPart))) {
|
|
|
|
$htmlPart = $this->renderWith($htmlTemplate, $this->getData());
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 05:09:14 +02:00
|
|
|
// Plain part fails over to generated from html
|
|
|
|
if (!$plainPart && $htmlPart) {
|
|
|
|
/** @var DBHTMLText $htmlPartObject */
|
|
|
|
$htmlPartObject = DBField::create_field('HTMLFragment', $htmlPart);
|
|
|
|
$plainPart = $htmlPartObject->Plain();
|
|
|
|
}
|
2019-06-14 12:39:47 +02:00
|
|
|
|
2018-08-14 17:26:31 +02:00
|
|
|
// Rendering is finished
|
|
|
|
Requirements::restore();
|
2017-10-18 05:09:14 +02:00
|
|
|
|
|
|
|
// Fail if no email to send
|
|
|
|
if (!$plainPart && !$htmlPart) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build HTML / Plain components
|
|
|
|
if ($htmlPart && !$plainOnly) {
|
|
|
|
$this->setBody($htmlPart);
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->setContentType('text/html');
|
|
|
|
$this->getSwiftMessage()->setCharset('utf-8');
|
|
|
|
if ($plainPart) {
|
|
|
|
$this->getSwiftMessage()->addPart($plainPart, 'text/plain', 'utf-8');
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-10-18 05:09:14 +02:00
|
|
|
} else {
|
2017-01-13 02:48:46 +01:00
|
|
|
if ($plainPart) {
|
|
|
|
$this->setBody($plainPart);
|
|
|
|
}
|
|
|
|
$this->getSwiftMessage()->setContentType('text/plain');
|
|
|
|
$this->getSwiftMessage()->setCharset('utf-8');
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
/**
|
|
|
|
* @return Swift_MimePart|false
|
|
|
|
*/
|
|
|
|
public function findPlainPart()
|
|
|
|
{
|
|
|
|
foreach ($this->getSwiftMessage()->getChildren() as $child) {
|
|
|
|
if ($child instanceof Swift_MimePart && $child->getContentType() == 'text/plain') {
|
|
|
|
return $child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function hasPlainPart()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-10-18 05:09:14 +02:00
|
|
|
if ($this->getSwiftMessage()->getContentType() === 'text/plain') {
|
2017-01-13 02:48:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return (bool) $this->findPlainPart();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 02:48:46 +01:00
|
|
|
* Automatically adds a plain part to the email generated from the current Body
|
2016-11-29 00:31:16 +01:00
|
|
|
*
|
2017-01-13 02:48:46 +01:00
|
|
|
* @return $this
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-01-13 02:48:46 +01:00
|
|
|
public function generatePlainPartFromBody()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-11-08 16:32:51 +01:00
|
|
|
$plainPart = $this->findPlainPart();
|
|
|
|
if ($plainPart) {
|
|
|
|
$this->getSwiftMessage()->detach($plainPart);
|
|
|
|
}
|
|
|
|
unset($plainPart);
|
|
|
|
|
2017-01-13 02:48:46 +01:00
|
|
|
$this->getSwiftMessage()->addPart(
|
|
|
|
Convert::xml2raw($this->getBody()),
|
|
|
|
'text/plain',
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|