Permalink
Browse files

Added support for HTML and plain-text in one message

  • Loading branch information...
1 parent e75597a commit df80cab691ce6b5fbcd6410ae398287f14c7848c @joelcox joelcox committed Feb 28, 2011
Showing with 32 additions and 21 deletions.
  1. +2 −0 .gitignore
  2. +6 −3 README.md
  3. +10 −16 controllers/test_amazon_ses.php
  4. +14 −2 libraries/Amazon_ses.php
View
@@ -25,3 +25,5 @@ libraries/index.html
models/
third_party/
views/
+logs/
+libraries/Curl.php
View
@@ -34,10 +34,13 @@ These three methods expect valid e-mail addresses as a string, array or comma se
###Message
####$this->amazon_ses->subject()
-Set the subject for a message
+Set the subject for a message.
-####$this->amazon_ses->$this->amazon_ses->message()
-Set the message to ben sent
+####$this->amazon_ses->message()
+Set the message to be sent.
+
+####$this->amazon_ses->message_alt()
+Set the alternative message (plain-text) to be sent. When not specified, an alternative message is generated by using PHP's strip_tags() function.
####$this->amazon_ses->send()
Sends the message. Returns true on success.
@@ -1,24 +1,22 @@
-<?php
+<?php
/**
* Small test suite for the Amazon Simple Email Service library
*
* @see /application/libraries/Amazon_ses.php
*/
-if (! defined('BASEPATH')) exit('No direct script access');
-
-class Test_amazon_ses extends CI_Controller {
-
+if (! defined('BASEPATH')) exit('No direct script access');
+
+class Test_amazon_ses extends CI_Controller {
+
function __construct(){
parent::__construct();
}
-
- function index() {
+
+ function index() {
// Surpress notices
- error_reporting(E_ALL);
-
- $this->load->library(array('amazon_ses', 'unit_test'));
+ error_reporting(0);
// Make sure we're running in strict test mode
$this->unit->use_strict(TRUE);
@@ -56,17 +54,13 @@ function index() {
$this->unit->run($this->amazon_ses->recipients['to'][3], 'test3@example.com', 'Set to address (array) (3)', '-');
$this->unit->run($this->amazon_ses->recipients['to'][4], 'test4@example.com', 'Set to address (array) (4)', '-');
-
-
// Set subject
$this->amazon_ses->subject('Subject');
$this->unit->run($this->amazon_ses->subject, 'Subject', 'Set message subject', '-');
// Display all results
echo $this->unit->report();
-
-
- }
-
+ }
+
}
View
@@ -147,7 +147,7 @@ public function subject($subject)
}
/**
- * Sets the message message
+ * Sets the message
* @param string the message
* @return void
*/
@@ -156,6 +156,16 @@ public function message($message)
$this->message = $message;
}
+ /**
+ * Sets the alternative message (plain-text) for when HTML email is not supported by email client
+ * @param string the message
+ * @return void
+ */
+ public function message_alt($message_alt)
+ {
+ $this->message_alt = $message_alt;
+ }
+
/**
* Sends off the email
* @param boolean whether to empty the $recipients array on success
@@ -295,7 +305,9 @@ private function _format_query_string()
'Action' => 'SendEmail',
'Source' => $this->from,
'Message.Subject.Data' => $this->subject,
- 'Message.Body.Text.Data' => $this->message
+ 'Message.Body.Text.Data' => (empty($this->message_alt) ? strip_tags($this->message) : $this->message_alt),
+ 'Message.Body.Html.Data' => $this->message
+
);
// Add all recipients to array

0 comments on commit df80cab

Please sign in to comment.