mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-26 20:45:47 +02:00
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@56212 467b73ca-7a2a-4603-9d3b-597d59a354a9
82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage email
|
|
*/
|
|
class TestMailer extends Mailer {
|
|
protected $emailsSent = array();
|
|
|
|
/**
|
|
* Send a plain-text email.
|
|
* TestMailer will merely record that the email was asked to be sent, without sending anything.
|
|
*/
|
|
function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customHeaders = false) {
|
|
$this->emailsSent[] = array(
|
|
'type' => 'plain',
|
|
'to' => $to,
|
|
'from' => $from,
|
|
'subject' => $subject,
|
|
|
|
'content' => $plainContent,
|
|
'plainContent' => $plainContent,
|
|
|
|
'attachedFiles' => $attachedFiles,
|
|
'customHeaders' => $customHeaders,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Send a multi-part HTML email
|
|
* TestMailer will merely record that the email was asked to be sent, without sending anything.
|
|
*/
|
|
function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customHeaders = false, $plainContent = false, $inlineImages = false) {
|
|
$this->emailsSent[] = array(
|
|
'type' => 'html',
|
|
'to' => $to,
|
|
'from' => $from,
|
|
'subject' => $subject,
|
|
|
|
'content' => $htmlContent,
|
|
'plainContent' => $plainContent,
|
|
'htmlContent' => $htmlContent,
|
|
|
|
'attachedFiles' => $attachedFiles,
|
|
'customHeaders' => $customHeaders,
|
|
'inlineImages' => $inlineImages,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Clear the log of emails sent
|
|
*/
|
|
function clearEmails() {
|
|
$this->emailsSent = array();
|
|
}
|
|
|
|
/**
|
|
* Search for an email that was sent.
|
|
* All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
|
|
* @param $to
|
|
* @param $from
|
|
* @param $subject
|
|
* @param $content
|
|
* @return An array containing the keys: 'type','to','from','subject','content', 'plainContent','attachedFiles','customHeaders','htmlContent',inlineImages'
|
|
*/
|
|
function findEmail($to, $from = null, $subject = null, $content = null) {
|
|
foreach($this->emailsSent as $email) {
|
|
$matched = true;
|
|
|
|
foreach(array('to','from','subject','content') as $field) {
|
|
if($value = $$field) {
|
|
if($value[0] == '/') $matched = preg_match($value, $email[$field]);
|
|
else $matched = ($value == $email[$field]);
|
|
if(!$matched) break;
|
|
}
|
|
}
|
|
|
|
if($matched) return $email;
|
|
}
|
|
}
|
|
|
|
|
|
} |