We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19309
    • 49 Posts
    Quote from: Frisco at Nov 16, 2009, 03:12 PM

    Have you changed the lang file as I described too?

    Yes, I did:

    $modx->TXNewsletters['txtlang']['confirmation_email_subject'] = 'Bitte bestätigen Sie die Bestellung Ihres kostenlosen Newsletter-Abonnements';
    


    And I also tried both versions (“À” as well as “ä”) just to see what happens. Both failed. Whereas, MS Outlook displays the “ä” correctly. But Webmail services can’t cope with it.

    Seems that I must have missed something, but I don’t know where to search yet.
      • 10190
      • 187 Posts
      hm, strange.

      Just to be absolutly sure: We are talking about the confirmation email for double-opt-in, right? And you added the function right before $subject is used with the mail() function, before the return?

      You could post your mail headers here, so I could compare them with mine - I didn’t check other mail clients then my thunderbird, but this is very important before sending out heaps of messed emails.

      Mine look like these (without the Received... and X-... headers):
      Message-ID: <[email protected]>
      Date: Mon, 16 Nov 2009 03:23:34 -0800 (PST)
      To: [email protected]
      Subject: =?ISO-8859-1?B?Qml0dGUgYmVzdOR0aWdlbiBTaWUgZGllIEJlc3RlbGx1bmcgSWg=?=
      =?ISO-8859-1?B?cmVzIGtvc3Rlbmxvc2VuIE5ld3NsZXR0ZXItQWJvbm5lbWVudHM=?=
      From: xxx Newsletter <[email protected]>
      MIME-Version: 1.0
      Content-Type: text/html; charset=UTF-8
      Content-Transfer-Encoding: 8bit

      Cheers
      Frisco
        • 22668
        • 718 Posts
        Is it time to rewrite TXNL to use PHPmailer? rolleyes
        Encoding problems should disappear.
          • 10190
          • 187 Posts
          I second that smiley

          And it should be not that difficult - as far as I got it there are only two functions which send email, and the header is puzzled there together by hand - should be some calls to PHPMailer from that function.

          Paprikas, would you give it a try?

          Cheers
          Frisco
            • 22668
            • 718 Posts
            Quote from: Frisco at Nov 16, 2009, 10:28 PM

            I second that smiley

            And it should be not that difficult - as far as I got it there are only two functions which send email, and the header is puzzled there together by hand - should be some calls to PHPMailer from that function.

            Paprikas, would you give it a try?

            Cheers
            Frisco

            Is this version is good to start from?
              • 24935
              • 160 Posts
              Here are some modifications I have made for a few sites. The code needs to be cleaned up and improved, but it does work.

              First, use PHPMailer. Notice I also allow an optional attachment to be specified via a TV. Obviously some things need to be moved into configuration variables.
                function sendNewsletterMail ($emails,$emailFrom,$newsletterId,$subject) {
                  global $modx;
              
                  $html = sendHTML($newsletterId);
              
                  require_once('controls/class.phpmailer.php');
                  $base_path = $modx->config['base_path'];
                  $tvs = $modx->getTemplateVarOutput('Attachment',$newsletterId);
                  $attachment = $base_path . $tvs['Attachment'];
                  foreach ($emails as $id => $datas) {
                    
                    $email = $datas['val'];
              
                    $timestamp = $datas['timestamp'];
                    $MD5 = ControlMD5($email,$timestamp);
                    $link = 'http://'.$_SERVER['HTTP_HOST'].'/index.php?&id='.$modx->TXNewsletters['idPageUnsubscribe'].'&action=del&email='.$email.'&control='.$MD5;
                    $send_html = preg_replace('#(\{link_unsubscribe\})#', $link, $html);
                    
                    $headers  = 'From: ' . $emailFrom . "\n";
                    $headers .= 'To: ' . $email . "\n";
                    $headers .= 'Return-Path: ' . $emailFrom . "\n";
                    $headers .= 'MIME-Version: 1.0' ."\n";
                    
                    $headers .= 'Content-Type: text/html; charset=UTF-8' ."\n";
                    $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
                    $headers .= $send_html . "\n";
                    
              //      $result=mail('', $subject,'', $headers);
              
                    $mail = new PHPMailer();
                    $mail->IsSMTP();
                    $mail->IsHTML(true);
                    $mail->From = $emailFrom;
                    $mail->FromName = '[Website Name Here]';
                    $mail->Subject = $subject;
                    $mail->Body = $send_html;
                    $mail->AddAddress($email);
                    if($attachment != $base_path) {
                      $mail->AddAttachment($attachment);
                    }
                    if(!$mail->send())
                      echo $mail->ErrorInfo,'<br>';
                    $result=true;
              
                  }
                  return $result;
                }
              


              Next is some tweaks to get a plain newsletter. I wanted the newletters to appear on the website with the normal site template, only the content (and an unsubscribe link) to be sent in the emails. This code is a little tricky...would be nice to get some input on it from someone more familiar with the parser (perhaps this is a very bad idea!)

                function sendHTML ($newsletterId) {
                  global $modx;
              
                  $modxout = new DocumentParser;
                  $modxout->documentIdentifier=$newsletterId;
                  $modxout->documentMethod= 'id';
                  $modxout->documentObject= $modxout->getDocumentObject($modxout->documentMethod, $modxout->documentIdentifier);
                  $modxout->documentName= $modxout->documentObject['pagetitle'];
                  $modxout->documentContent= '<h3>[!Title!]</h3>[*content*]<p><a href="{link_unsubscribe}">unsubscribe</a></p>'; // use blank template
                  $modxout->documentContent= $modxout->parseDocumentSource($modxout->documentContent);
                  ob_start();
                  ob_start();
                  $modxout->outputContent();
                  $html = ob_get_contents();
                  ob_end_clean();
              /*    
                  ini_set('default_socket_timeout', 120);
                  $url = 'http://'.$_SERVER['HTTP_HOST'].$modx->makeUrl($newsletterId);
                  $html = file_get_contents($url);    
              */
                  $httpDom = 'http://'.$_SERVER['HTTP_HOST'];
              //    $httpDom = $modx->config['base_url'];
              
                  $html = preg_replace('#(<img[^>]*src=\")([^\"]*/?assets/)#', '${1}'.$httpDom.'/assets/', $html);
                  $html = preg_replace('#(<a[^>]*href=\")([^\"]*/?assets/)#', '${1}'.$httpDom.'/assets/', $html);
                  $html = preg_replace('#(<a[^>]*href=\")([^\"]*/?index\.php)#', '${1}'.$httpDom.'/index.php', $html);
                  $html = preg_replace('#(onclick=\"window\.open\(\')([^\"]*/?assets/)#', '${1}'.$httpDom.'/assets/', $html);
                   
                  return $html;
                }
              


              Unfortunately too busy to fix up this module myself, so I thought I would share some of my modifications here for whomever has a little more time to put together the 1.0 version of TX Newsletters. smiley
                • 22668
                • 718 Posts
                Thanks!
                  • 10190
                  • 187 Posts
                  Quote from: Paprikas at Nov 18, 2009, 08:02 AM

                  ...
                  Is this version is good to start from?

                  Yes, that’s the version I use too.

                  Cheers, Frisco
                    • 10190
                    • 187 Posts
                    rfoster, thanks for sharing!

                    It’s great just to mention things like integration with PHPMailer and zack, someone comes up with the code ready! smiley

                    BTW, do you know how this works with different mail clients? Maybe you got some feedback of your newsletter subscribers?

                    I can’t say anything about the second code part, as I don’t know ModX insides.

                    I suppose the owner of TXNewsletters would be the best person to bring all these together for v1.0, and I’d recommend modifying sendConfirmation() the same way as sendNewsletterMail (...).

                    Cheers
                    Frisco
                      • 25260
                      • 156 Posts
                      do you think it’s better to go with phpMailer or with Pear Mail?