Skip to content

Commit

Permalink
Merge pull request #34 from kinoheld/composer
Browse files Browse the repository at this point in the history
Updated PHPMailer to latest 6.x release
  • Loading branch information
vernes authored Feb 7, 2018
2 parents 8a40971 + 496998a commit 91640f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii (v1.1.x) extension for sending emails with layouts using [PHPMailer](https:/

## Features

* Based on PHPMailer (bundled, use branch 'composer' for composer support)
* Based on PHPMailer
* Supports Yii layouts and translation
* Supports web and console applications
* Send full HTML emails with embedded images
Expand All @@ -13,8 +13,8 @@ Yii (v1.1.x) extension for sending emails with layouts using [PHPMailer](https:/


## Installation
1. Copy YiiMailer folder to protected/extensions
2. Add 'ext.YiiMailer.YiiMailer' line to your imports in main and/or console yii config
1. Install with composer: `composer require rdewilde/yiimailer`
2. Add 'vendor.rdewilde.yiimailer.YiiMailer' line to your imports in main and/or console yii config
3. Copy mail.php config file to protected/config or add configuration array in 'params' under the key 'YiiMailer'
4. Create email layout file mail.php in protected/views/layouts/ (default path, can be changed in config)
5. Create all the views you want to use in protected/views/mail/ (default path, can be changed in config)
Expand Down
47 changes: 21 additions & 26 deletions YiiMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
* @author Vernes Šiljegović
* @copyright Copyright (c) 2014 YiiMailer
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6, 2014-07-09
* @version 2.0.0, 2018-02-06
*/

use PHPMailer\PHPMailer\PHPMailer;

class YiiMailer extends PHPMailer
{
Expand All @@ -37,12 +38,6 @@ class YiiMailer extends PHPMailer
*/
public $CharSet = 'UTF-8';

/**
* Sets the text-only body of the message.
* @var string
*/
public $AltBody = '';

/**
* Default paths and private properties
*/
Expand Down Expand Up @@ -323,7 +318,7 @@ public function getBaseDirPath()
*/
public function setFrom($address, $name = '', $auto = true)
{
return parent::SetFrom($address, $name, (int)$auto);
return parent::setFrom($address, $name, (bool)$auto);
}

/**
Expand All @@ -337,7 +332,7 @@ public function setFrom($address, $name = '', $auto = true)
*/
public function setTo($addresses)
{
$this->ClearAddresses();
$this->clearAddresses();
return $this->setAddresses('to', $addresses);
}

Expand All @@ -348,7 +343,7 @@ public function setTo($addresses)
*/
public function setCc($addresses)
{
$this->ClearCCs();
$this->clearCCs();
return $this->setAddresses('cc', $addresses);
}

Expand All @@ -359,7 +354,7 @@ public function setCc($addresses)
*/
public function setBcc($addresses)
{
$this->ClearBCCs();
$this->clearBCCs();
return $this->setAddresses('bcc', $addresses);
}

Expand All @@ -370,7 +365,7 @@ public function setBcc($addresses)
*/
public function setReplyTo($addresses)
{
$this->ClearReplyTos();
$this->clearReplyTos();
return $this->setAddresses('Reply-To', $addresses);
}

Expand All @@ -389,9 +384,9 @@ private function setAddresses($type, $addresses)
$result = true;
foreach ($addresses as $key => $value) {
if (is_int($key))
$r = $this->AddAnAddress($type, $value);
$r = $this->addAnAddress($type, $value);
else
$r = $this->AddAnAddress($type, $key, $value);
$r = $this->addAnAddress($type, $key, $value);
if ($result && !$r)
$result = false;
}
Expand Down Expand Up @@ -434,9 +429,9 @@ public function setAttachment($attachments)
$result = true;
foreach ($attachments as $key => $value) {
if (is_int($key))
$r = $this->AddAttachment($value);
$r = $this->addAttachment($value);
else
$r = $this->AddAttachment($key, $value);
$r = $this->addAttachment($key, $value);
if ($result && !$r)
$result = false;
}
Expand All @@ -449,9 +444,9 @@ public function setAttachment($attachments)
*/
public function clear()
{
$this->ClearAllRecipients();
$this->ClearReplyTos();
$this->ClearAttachments();
$this->clearAllRecipients();
$this->clearReplyTos();
$this->clearAttachments();
}

/**
Expand Down Expand Up @@ -543,7 +538,7 @@ public function render()
*/
protected function MsgHTMLWithLayout($message, $basedir = '')
{
$this->MsgHTML($this->renderView($this->layoutPath . '.' . $this->layout, array('content' => $message, 'data' => $this->data)), $basedir);
$this->msgHTML($this->renderView($this->layoutPath . '.' . $this->layout, array('content' => $message, 'data' => $this->data)), $basedir);
}

/**
Expand All @@ -558,17 +553,17 @@ public function send()
//send the message
try {
//prepare the message
if (!$this->PreSend())
if (!$this->preSend())
return false;

//in test mode, save message as a file
if ($this->testMode)
return $this->save();
else
return $this->PostSend();
} catch (phpmailerException $e) {
return $this->postSend();
} catch (Exception $e) {
$this->mailHeader = '';
$this->SetError($e->getMessage());
$this->setError($e->getMessage());
if ($this->exceptions) {
throw $e;
}
Expand Down Expand Up @@ -597,12 +592,12 @@ public function save()

try {
$file = fopen($dir . DIRECTORY_SEPARATOR . $filename, 'w+');
fwrite($file, $this->GetSentMIMEMessage());
fwrite($file, $this->getSentMIMEMessage());
fclose($file);

return true;
} catch (Exception $e) {
$this->SetError($e->getMessage());
$this->setError($e->getMessage());

return false;
}
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "rdewilde/yiimailer",
"description": "Yii extension for sending emails with layouts using PHPMailer",
"type": "yii-extension",
"require": {
"php": ">=5.0.0",
"phpmailer/phpmailer": "5.2.*"
"php": ">=5.0.0",
"phpmailer/phpmailer": "^6.0"
}
}

0 comments on commit 91640f2

Please sign in to comment.