Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Email Library
  • Does Fuel have any plans for an email class, or is it suggested we use something like swiftmailer?
  • Is there any progress yet? Is someone creating something? If not... I could give a shot. x)
  • Raitis Stengrevics wrote on Monday 30th of May 2011:
    Is there any progress yet? Is someone creating something? If not... I could give a shot. x)

    No one is doing it as I know of :(
  • Hello It has one built in, but it could be buggy yet... Try smth like this:
            Email::factory()
                ->subject('test sub')
                //->from('info@invista.lt')
                ->to('info@invista.lt')
                ->message('message')
                ->set_alt_message('message txt')
                ->send();
            
            Email::print_debugger();
    
    

    fele free to make Swiftmailer package and share with us :))))
  • I might just do that! I do very much like swiftmailer... For now, I was just after a quick and dirty email so I'll give that code a go, thanks.
  • The problem with the current email class, and the reason it's not documented, is that large chunks of it were taken from CodeIgniter and CI's license isn't compatible with our MIT license. Thus for the official final release we can't include this lib. Dan had some plans for writing a new Email lib using parts of the Zend Mail class with a Fuel interface, but I don't think there has been any progress on that front yet.
  • Hi daGrevis Have you managed to make any progress on an email class for Fuel yet? Jelmer mentioned that either he or Dan were looking into converting the Zend one do you know if this has progressed at all? I have been using Swiftmailer just a 1 line integration was all that was required. Steps: download swiftmailer. copy the swift folder in to packages create a file called bootstrap in the root of the swift folder (Same as auth and orm packages) Here is my bootstrap.php
    <?php
    /**
     * Fuel is a fast, lightweight, community driven PHP5 framework.
     *
     * @package    Fuel
     * @version    1.0
     * @author     Fuel Development Team
     * @license    MIT License
     * @copyright  2010 - 2011 Fuel Development Team
     * @link       http://fuelphp.com
     */
    
    require_once __DIR__.'/lib/swift_required.php';
    
    /* End of file bootstrap.php */
    
    

    in app/config/config.php add it to your packages like so...
    'packages' => array(
                'auth',
                'swift'
       //'orm',
      ),
    

    or use Fuel::add_package('swift'); in your controller and my test controller...
    class Controller_Testmail extends Controller &#123;
    
     /**
      * The index action.
      *
      * @access  public
      * @return  void
      */
     public function action_index()
     &#123;
    
        $Transport  = Swift_MailTransport::newInstance();
        $Mailer     = Swift_Mailer::newInstance($Transport);
        $message    = Swift_Message::newInstance()
    
        //Give the message a subject
        ->setSubject('Test subject')
    
        //Set the From address with an associative array
        ->setFrom(array('local1@localhost.com' => 'Local1 Localhost'))
    
        //Set the To addresses with an associative array
        ->setTo(array('info@localhost.com' => 'Test Name'))
    
        //Give it a body
        ->setBody('Here is the message itself')
    
        //And optionally an alternative body
        ->addPart('<p style="color: #336699;"><q>Here is the message itself in it\'s various guises</q></p>', 'text/html')
    
        //Optionally add any attachments
        //->attach(Swift_Attachment::fromPath('my-document.pdf'))
        ;
    
        $Mailer->send($message);
    
        $this->response->body = View::factory('welcome/index');
    
        }
    
    }
    
    

    Seems to work ok well at least no issues yet ... Hope this helps someone. Phil.
  • It would be nice to convert this into a driver architecture, and abstract these calls into the driver, so you can do
    class Controller_Testmail extends Controller {
    
        public function action_index() {
    
            $email = new \Email\Email::factory('swift'); // assume the package is called 'Email'
    
            // use generic methods here
            $email ->subject('Test subject')
                        ->from(array('local1@localhost.com' => 'Local1 Localhost'))
                        ->to(array('info@localhost.com' => 'Test Name'))
                        ->body('Here is the message itself')
                        ->part('<p style="color: #336699;"><q>Here is the message itself in it\'s various guises</q></p>', 'text/html');
    
            // add an attachment
            $email->attach('my-document.pdf'));
    
            // send the message
            if ($result = $email->send())
            {
                // successfully send
            } 
            else
            {
                // process the error
            }
    }
    
    It will allow you to swap the swift driver by any other driver, which doesn't even have to send out a real email (it could generate a forum post somewhere for example), which gives you total flexibility, fuel style. See Jelmer's fuel-parser as a good example of how to set something like this up (or checkout the old Email class)...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion