mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-26 22:02:13 +09:00
80 lines
1.6 KiB
PHP
80 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Rhymix\Framework\Drivers\Mail;
|
|
|
|
/**
|
|
* The Amazon SES mail driver.
|
|
*/
|
|
class SES extends Base implements \Rhymix\Framework\Drivers\MailInterface
|
|
{
|
|
/**
|
|
* Cache the message here for debug access.
|
|
*/
|
|
protected $_message;
|
|
|
|
/**
|
|
* Direct invocation of the constructor is not permitted.
|
|
*/
|
|
protected function __construct(array $config)
|
|
{
|
|
$transport = \Swift_AWSTransport::newInstance($config['user'], $config['pass']);
|
|
$transport->setDebug(array($this, 'debugCallback'));
|
|
$transport->setEndpoint('https://email.' . strtolower($config['type']) . '.amazonaws.com/');
|
|
$this->mailer = \Swift_Mailer::newInstance($transport);
|
|
}
|
|
|
|
/**
|
|
* Check if the current mail driver is supported on this server.
|
|
*
|
|
* This method returns true on success and false on failure.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function isSupported()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Send a message.
|
|
*
|
|
* This method returns true on success and false on failure.
|
|
*
|
|
* @param object $message
|
|
* @return bool
|
|
*/
|
|
public function send(\Rhymix\Framework\Mail $message)
|
|
{
|
|
$this->_message = $message;
|
|
|
|
try
|
|
{
|
|
$result = $this->mailer->send($message->message, $errors);
|
|
}
|
|
catch(\Exception $e)
|
|
{
|
|
$message->errors[] = $e->getMessage();
|
|
return false;
|
|
}
|
|
|
|
foreach ($errors as $error)
|
|
{
|
|
$message->errors[] = $error;
|
|
}
|
|
return (bool)$result;
|
|
}
|
|
|
|
/**
|
|
* Debug callback function for SES transport.
|
|
*
|
|
* @param string $msg
|
|
* @return void
|
|
*/
|
|
public function debugCallback($msg)
|
|
{
|
|
if ($this->_message)
|
|
{
|
|
$this->_message->errors[] = $msg;
|
|
}
|
|
}
|
|
}
|