Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS3 + swiftmailer problem, worked with SS2,4

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

Page: 1
Go to End
Author Topic: 637 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    SS3 + swiftmailer problem, worked with SS2,4 Link to this post

    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

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: SS3 + swiftmailer problem, worked with SS2,4 Link to this post

    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/

  • arnhoe
    Avatar
    Community Member
    6 Posts

    Re: SS3 + swiftmailer problem, worked with SS2,4 Link to this post

    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?

    637 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.