linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file template_newsletter.php

Documentation is available at template_newsletter.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage mail
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12. /**
  13.  * absolute_url
  14.  * http://www.howtoforge.com/forums/showthread.php?t=4
  15.  * @param $txt 
  16.  * @param $base_url 
  17.  */
  18. function absolute_url($txt$base_url{
  19.   $needles array('href="''src="''background="');
  20.   $new_txt '';
  21.   if(substr($base_url,-1!= '/'$base_url .= '/';
  22.   $new_base_url $base_url;
  23.   $base_url_parts parse_url($base_url);
  24.  
  25.   foreach($needles as $needle){
  26.     while($pos strpos($txt$needle)){
  27.       $pos += strlen($needle);
  28.       if(substr($txt,$pos,7!= 'http://' && substr($txt,$pos,8!= 'https://' && substr($txt,$pos,6!= 'ftp://' && substr($txt,$pos,9!= 'mailto://'){
  29.         if(substr($txt,$pos,1== '/'$new_base_url $base_url_parts['scheme'].'://'.$base_url_parts['host'];
  30.         $new_txt .= substr($txt,0,$pos).$new_base_url;
  31.       else {
  32.         $new_txt .= substr($txt,0,$pos);
  33.       }
  34.       $txt substr($txt,$pos);
  35.     }
  36.     $txt $new_txt.$txt;
  37.     $new_txt '';
  38.   }
  39.   return $txt;
  40. }
  41.  
  42. require_once '../lib/vendor/swift/lib/swift_required.php';
  43.  
  44. // We create the Transport
  45. if (defined('MAIL_MAILER')) {
  46.     
  47.     // by default
  48.     $transport Swift_MailTransport::newInstance();
  49.  
  50.     // sendmail
  51.     if(MAIL_MAILER=='sendmail'{
  52.         
  53.         $transport Swift_SendmailTransport::newInstance(MAIL_SENDMAIL);
  54.         
  55.     }
  56.     // smtp
  57.     if(MAIL_MAILER=='smtp'{
  58.         if(defined('MAIL_SMTP_AUTH'&& MAIL_SMTP_AUTH == 1{
  59.             
  60.             $transport Swift_SmtpTransport::newInstance(MAIL_HOSTMAIL_PORT)
  61.             ->setUsername(MAIL_SMTP_USER)
  62.             ->setPassword(MAIL_SMTP_PASS);
  63.             
  64.         else {
  65.             
  66.             $transport Swift_SmtpTransport::newInstance(MAIL_HOSTMAIL_PORT);
  67.             
  68.         }
  69.  
  70.     }
  71.     
  72. }
  73.  
  74. // Create the Mailer using the Transport
  75. $mailer Swift_Mailer::newInstance($transport);
  76.  
  77. /**
  78.  echo "destinataire : ".$email_recipient."<br />";
  79.  echo "sujet : ".$email_subject."<br />";
  80.  echo "body : ".$email_html_body."<br />";
  81.  echo "methode : ".$email_method."<br />";
  82.  echo "host : ".$mail->Host."<br />";
  83.  echo "port : ".$mail->Port."<br />";
  84.  */
  85.  
  86. for($i 0;$i count($newsletters)$i++{
  87.   $newsletter_id $newsletters[$i]['newsletter_id'];
  88.   $email_subject formatText($newsletters[$i]['newsletter_title']'2HTML');
  89.  
  90.   $newsletter_body_html formatText($newsletters[$i]['newsletter_body']'2HTML');
  91.   preg_replace("/(<\s*(a|img)\s+[^>]*(href|src)\s*=\s*[\"'])(?!http)([^\"'>]+)[\"'>]/""$1".CURRENT_APP_URL."$4"$newsletter_body_html);
  92.   $email_html_body=str_replace('##TITLE##'$email_subject$template_html);
  93.   $email_html_body=str_replace('##CHARSET##'CHARSET$email_html_body);
  94.   $email_html_body=str_replace('##CONTENTS##'$newsletter_body_html$email_html_body);
  95.   $email_html_body=str_replace('##SITENAME##'SITE_NAME$email_html_body);
  96.   $email_html_body=str_replace('##CSSPATH##'SITE_ROOT_URLTHEME_DIRECTORY.'/public/'.THEME_PUBLIC.'/css/'$email_html_body);
  97.   $email_html_body=str_replace('##SITEURL##'SITE_ROOT_URL$email_html_body);
  98.   $email_html_body=str_replace('##SITEMAIL##'SITE_MAIL$email_html_body);
  99.   $email_html_body=absolute_url($email_html_bodySITE_ROOT_URL);
  100.  
  101.   $newsletter_body_txt formatText($newsletters[$i]['newsletter_body']);
  102.   $email_text_body=str_replace('##TITLE##'strip_tags(formatText($email_subject))$template_txt);
  103.   $email_text_body=str_replace('##CONTENTS##'strip_tags(formatText($newsletter_body_txt))$email_text_body);
  104.   $email_text_body=str_replace('##SITENAME##'SITE_NAME$email_text_body);
  105.   $email_text_body=str_replace('##SITEURL##'SITE_ROOT_URL$email_text_body);
  106.   $email_text_body=str_replace('##SITEMAIL##'SITE_MAIL$email_text_body);
  107.   $email_text_body=absolute_url($email_text_bodySITE_ROOT_URL);
  108.   
  109.   
  110.   isset($email_from$from $email_from $from MAIL_FROM;
  111.   isset($email_fromname$fromname $email_fromname $fromname MAIL_FROMNAME;
  112.   $altbody str_replace('&amp;''&'$email_text_body);
  113.   
  114.   // Create a message
  115.   $message Swift_Message::newInstance($email_subject)
  116.   ->setFrom(array($from => $fromname))
  117.   ->setBody($email_html_body'text/html')
  118.   ->addPart($altbody'text/plain')
  119.   ->setReplyTo(array(MAIL_REPLY => MAIL_REPLYNAME))
  120.   ;
  121.   
  122.  
  123.   for($k 0$k count($emails_batch)$k++{
  124.     $email_id $emails_batch[$k]['emailcol_id'];
  125.     $email_recipient $emails_batch[$k]['emailcol_email'];
  126.  
  127.       $message->setTo($email_recipient);
  128.         $r $mailer->Send($message$failures);
  129.         
  130.         if(!$r
  131.             $logmsg 'not sent';
  132.         else {
  133.             $logmsg 'sent';
  134.         }
  135.         
  136.         logfile(LOG_MAILINGarray($email_subject$newsletter_id$email_recipient$logmsg));
  137.         
  138.   }
  139.   
  140.   if(!isset($doNotPublish)) $newsletter_object->SetNewsletterPublished($newsletter_id$sql_object);
  141. }
  142.  
  143. ?>

Documentation generated on Mon, 08 Apr 2013 18:16:25 +0200 by phpDocumentor 1.4.1