Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Swiftmailer with Fuel
  • 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       [url=http://fuelphp.com]http://fuelphp.com[/url]
     */
    
    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.

Howdy, Stranger!

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