Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

SS3 + swiftmailer problem, worked with SS2,4


Reply

3 Posts   653 Views

Avatar
danzzz

5 October 2012 at 9:26pm Community Member, 175 Posts

hi,

I have problems with SS3 and swiftmailer.
With SS2.4 there are not any problems, I integrated swiftmailer this way:

In /swiftmailer/code are all swiftmailer files

/swiftmailer/_config.php

<?php

require(dirname( __FILE__ )."/code/swift_required.php");

and this is my swiftmailer class to call swiftmailer:

<?php

class SwiftMailer {

   private $smtphost;
   private $port;
   private $user;
   private $password;
   private $mailer;
   private $message;

   private $textpart;
   private $htmlpart;

   public $sender;
   public $receiver;
   public $subject;
   public $texttemplate;
   public $htmltemplate;
   public $templatedata;

   public function __construct() {
   

      $this->smtphost = 'localhost';
      $this->port = 25;
      $this->user = 'noreply@xxx';
      $this->password = 'xxx';

      $transport = Swift_SmtpTransport::newInstance($this->smtphost, $this->port)
         ->setUsername($this->user)
         ->setPassword($this->password);

debug::dump($transport);
   
      if(!isset($this->sender)) {
         $this->sender = array('noreply@xxx' => 'Sender Name');
      }
   
      $this->mailer = Swift_Mailer::newInstance($transport);
      $this->message = Swift_Message::newInstance();
   
   }

   public function send() {

      $this->message->setFrom($this->sender);
      $this->message->setTo($this->receiver);
      $this->message->setSubject($this->subject);

      if(isset($this->templatedata) && !empty($this->templatedata)) {
         $templatedata = new ArrayData($this->templatedata);
      } else {
         $templatedata = new ArrayData(array());
      }

      $this->textpart = $templatedata->renderWith($this->texttemplate);
      $this->message->setBody($this->textpart);
      if(isset($this->htmltemplate) && !empty($this->htmltemplate)) {
         $this->htmlpart = $templatedata->renderWith($this->htmltemplate);
         $this->message->addPart($this->htmlpart,'text/html');
      }

      $result = $this->mailer->send($this->message);

      return $result;
   
   }

}

as mentioned, this works perfect with ss2.4 but not with ss3, there are serveral swiftmailer errors like this one:

ERROR [Notice]: Undefined variable: buf
IN POST /xxx/inquiry
Line 56 in /var/www/vhosts/xxx/httpdocs/yyy/swiftmailer/code/classes/Swift/Transport/EsmtpTransport.php

so what can be the difference here? any ideas? is there anything changed in SS3 regarding to implementing 3rd party stuff?

thx

Avatar
danzzz

6 October 2012 at 2:49am Community Member, 175 Posts

I now use Zend_Mail (V 1.12) with SS3.

Just copy this 3 components from the ZF to /framework/thirdparty/Zend/

Mail (incl. Mail.php)
Mime (incl. Mime.php)
Validator (incl. Valitator.php) needed for SMTP

or copy it to your dev dirs if you dont want t touch /framework/ :D

Avatar
arnhoe

1 November 2012 at 9:04am Community Member, 6 Posts

Hi danzzz,

Thanks for your fix, but unfortuantly I didn't get it working. I am having lots of troubles at this moment with UserForms, since I cannont sent mails to emails of the domain, the website is hosted on. I used SMTPMailer in SilverStripe 2.4.*.

Is it possible that you can elaborate your last post a little more?

Or does this trick doesn't work for UserForms?