Skip to content

Instantly share code, notes, and snippets.

@AmyStephen
Last active August 29, 2015 13:57

Revisions

  1. AmyStephen revised this gist Mar 8, 2014. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions email.php
    Original file line number Diff line number Diff line change
    @@ -86,19 +86,19 @@ class Swiftmailer extends AbstractHandler implements EmailInterface
    $class = 'Molajo\\Email\\Swiftmailer';
    $handler = new $class($options);

    // 2. Instantiate the Adapter, injecting it with the Handler.
    // 2. Instantiate the Email class, injecting it with the Handler.
    $class = 'Molajo\\Email';
    $this->adapter = new $class($handler);
    $email = new $class($handler);

    // 3. Set email parameters
    $this->adapter->set('to', '[email protected],Fname Lname');
    $this->adapter->set('from', '[email protected],Fname Lname');
    $this->adapter->set('reply_to', '[email protected],FName LName');
    $this->adapter->set('cc', '[email protected],FName LName');
    $this->adapter->set('bcc', '[email protected],FName LName');
    $this->adapter->set('subject', 'Welcome to our Site');
    $this->adapter->set('body', 'Stuff goes here');
    $this->adapter->set('mailer_html_or_text', 'text');
    $email->set('to', '[email protected],Fname Lname');
    $email->set('from', '[email protected],Fname Lname');
    $email->set('reply_to', '[email protected],FName LName');
    $email->set('cc', '[email protected],FName LName');
    $email->set('bcc', '[email protected],FName LName');
    $email->set('subject', 'Welcome to our Site');
    $email->set('body', 'Stuff goes here');
    $email->set('mailer_html_or_text', 'text');

    // 4. Send Email.
    $this->adapter->send();
    $email->send();
  2. AmyStephen revised this gist Mar 8, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions email.php
    Original file line number Diff line number Diff line change
    @@ -82,9 +82,8 @@ class Swiftmailer extends AbstractHandler implements EmailInterface
    $options = array();
    $options['mailer_transport'] = 'mail';
    $options['site_name'] = 'Sitename';
    $options['Fieldhandler'] = new Fieldhandler();

    $class = 'Molajo\\Email\\Handler\\Swiftmailer';
    $class = 'Molajo\\Email\\Swiftmailer';
    $handler = new $class($options);

    // 2. Instantiate the Adapter, injecting it with the Handler.
  3. AmyStephen created this gist Mar 8, 2014.
    105 changes: 105 additions & 0 deletions email.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    <?php
    class Email implements EmailInterface
    {
    /**
    * Email Handler
    *
    * @var object
    * @since 1.0
    */
    protected $handler;

    /**
    * Constructor
    *
    * @param EmailInterface $email
    *
    * @since 1.0
    */
    public function __construct(EmailInterface $email)
    {
    $this->handler = $email;
    }

    /**
    * Return parameter value or default
    *
    * @param string $key
    * @param string $default
    *
    * @return mixed
    * @since 1.0
    */
    public function get($key, $default = null)
    {
    return $this->handler->get($key, $default);
    }

    /**
    * Set parameter value
    *
    * @param string $key
    * @param mixed $value
    *
    * @return $this
    * @since 1.0
    */
    public function set($key, $value = null)
    {
    $this->handler->set($key, $value);

    return $this;
    }

    /**
    * Send Email
    *
    * @return mixed
    * @since 1.0
    */
    public function send()
    {
    $this->handler->send();

    return $this;
    }
    }

    class PhpMailer extends AbstractHandler implements EmailInterface
    {
    // get, set, send methods that interact with phpMailer
    }

    class Swiftmailer extends AbstractHandler implements EmailInterface
    {
    // get, set, send methods that interact with Swiftmailer
    }

    // To use


    // 1. Instantiate an Email Handler.
    $options = array();
    $options['mailer_transport'] = 'mail';
    $options['site_name'] = 'Sitename';
    $options['Fieldhandler'] = new Fieldhandler();

    $class = 'Molajo\\Email\\Handler\\Swiftmailer';
    $handler = new $class($options);

    // 2. Instantiate the Adapter, injecting it with the Handler.
    $class = 'Molajo\\Email';
    $this->adapter = new $class($handler);

    // 3. Set email parameters
    $this->adapter->set('to', '[email protected],Fname Lname');
    $this->adapter->set('from', '[email protected],Fname Lname');
    $this->adapter->set('reply_to', '[email protected],FName LName');
    $this->adapter->set('cc', '[email protected],FName LName');
    $this->adapter->set('bcc', '[email protected],FName LName');
    $this->adapter->set('subject', 'Welcome to our Site');
    $this->adapter->set('body', 'Stuff goes here');
    $this->adapter->set('mailer_html_or_text', 'text');

    // 4. Send Email.
    $this->adapter->send();